1.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.21.jar" />
<!-- targetRuntime:生成代码的运行环境 -->
<context id="MysqlTables" 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:3306/mybatis" userId="root"
password="cp3">
</jdbcConnection>
<!-- 类型转换信息 这里没用到 -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- entity配置 -->
<javaModelGenerator targetPackage="com.lzm.mybatis.entity"
targetProject="E:\workspace\mybatis\src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- dao配置 -->
<!-- dao -->
<sqlMapGenerator targetPackage="com.lzm.mybatis.dao"
targetProject="E:\workspace\mybatis\src\main\java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- mapper -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.lzm.mybatis.dao" targetProject="E:\workspace\mybatis\src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 配置不生成example类 -->
<table tableName="BLC_USER" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<columnOverride column="ID" property="id"
javaType="java.lang.Integer" jdbcType="NUMERIC" />
</table>
</context>
</generatorConfiguration>
2.
* classPathEntry :jdbc的类路径;
* commentGenerator :注释配置;
* jdbcConnection:jdbc连接信息;
* javaTypeResolver:类型转换的信息,这里并没有用到;
* javaModelGenerator:模型的生成信息,这里将指定这些Java model类的生成路径;
* sqlMapGenerator:mybatis 的sqlMapper XML文件的生成信息,包括生成路径等;
* javaClientGenerator:应用接口的生成信息;
* table:用户指定的被生成相关信息的表,它必须在指定的jdbc连接中已经被建立。
3.命令:java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite