• mybatis generator自动生成DAO,mapping,model


    1、相关文件是:

    关于Mybatis-Generator的下载可以到这个地址:https://github.com/mybatis/generator/releases

    ggg.xml文件的代码:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE generatorConfiguration
    PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
    "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
    <generatorConfiguration>
    <!--数据库驱动-->
    <classPathEntry location="mysql-connector-java-5.1.7-bin.jar"/>
    <context id="DB2Tables" targetRuntime="MyBatis3">
    <commentGenerator>
    <property name="suppressDate" value="true"/>
    <property name="suppressAllComments" value="true"/>
    </commentGenerator>
    <!--数据库链接地址账号密码-->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/cznm" userId="root" password="root">
    </jdbcConnection>
    <javaTypeResolver>
    <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>
    <!--生成Model类存放位置-->
    <javaModelGenerator targetPackage="lcw.model" targetProject="src">
    <property name="enableSubPackages" value="true"/>
    <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!--生成映射文件存放位置-->
    <sqlMapGenerator targetPackage="lcw.mapping" targetProject="src">
    <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>
    <!--生成Dao类存放位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="lcw.dao" targetProject="src">
    <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>
    <!--生成对应表及类名-->
    <table tableName="sys_area" domainObjectName="SysArea" ></table>
    <table tableName="role_module" domainObjectName="RoleModel" ></table>
    <table tableName="sys_company" domainObjectName="SysCompany" ></table>
    <table tableName="sys_company_visit" domainObjectName="SysCompanyVisit" ></table>
    <table tableName="sys_module" domainObjectName="SysModule" ></table>
    <table tableName="sys_news" domainObjectName="SysNews" ></table>
    <table tableName="sys_role" domainObjectName="SysRole" ></table>
    <table tableName="sys_user" domainObjectName="SysUser" ></table>
    </context>
    </generatorConfiguration>

    拷到文件里就行,

    需要修改文件配置的地方我都已经把注释标注出来了,这里的相关路径(如数据库驱动包,生成对应的相关文件位置可以自定义)不能带有中文。

    上面配置文件中的:

    <table tableName="message" domainObjectName="Messgae" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>

    tableName和domainObjectName为必选项,分别代表数据库表名和生成的实力类名,其余的可以自定义去选择(一般情况下均为false)。

    生成语句文件:

    java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

    2、使用方法

    在该目录按住Shift键,右键鼠标选择"在此处打开命令窗口",复制粘贴生成语句的文件代码即可。

    看下效果图:

    作者:战旗 内容声明: 本内容属自己学习使用 ,若有抄袭情邮件(zhanqi3712@qq.com)告知 ,本人会尽快删除
  • 相关阅读:
    她又在这个星期联系我了 20110422
    用心去做 20110307
    2011年随笔记
    让我有勇气坚持下去 20110427
    2011年随笔记 5月30号以后的日志薄
    因为迷失,所以 201103015
    迷失只是暂时 20110313
    我们做一对好哥们吧 20101228
    3.20号,她恢复了联系 20110320
    FW: Deploy reporting services web parts (RSWebParts) to SharePoint 2010
  • 原文地址:https://www.cnblogs.com/liuyun-10/p/6835891.html
Copyright © 2020-2023  润新知