mybatis 自动生成代码

1,下载mybatis-generator-core-1.3.1-bundle(我要带梯才下载回来)

2,在lib中加入mysql-connector-java-5.1.36.jar,mybatis-3.3.0.jar,generatorConfig.xml(配置在文章后面),src

3,完成上步骤后mybatis-generator-core-1.3.1-bundle中lib目录如下:

mybatis 自动生成代码_第1张图片

4,打开cmd 进入lib 中 执行脚本:

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

5,执行成功:


6,src中的代码:

mybatis 自动生成代码_第2张图片


generatorConfig.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.36.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://127.0.0.1/gzb" userId="root" password="root">    
        </jdbcConnection>    
        <javaTypeResolver>    
            <property name="forceBigDecimals" value="false"/>    
        </javaTypeResolver>    
        <javaModelGenerator targetPackage="com.model" targetProject="src">    
            <property name="enableSubPackages" value="true"/>    
            <property name="trimStrings" value="true"/>    
        </javaModelGenerator>    
        <sqlMapGenerator targetPackage="com.mapping" targetProject="src">    
            <property name="enableSubPackages" value="true"/>    
        </sqlMapGenerator>    
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.Idao" targetProject="src">    
            <property name="enableSubPackages" value="true"/>    
        </javaClientGenerator>    
        <table tableName="worker" domainObjectName="Worker" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>  
    </context>    
</generatorConfiguration>





你可能感兴趣的:(mybatis,自动生成代码)