MyBatis Generator配置文件翻译
<classPathEntry>
驱动文件指定配置项
<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />
<columnOverride>
将数据库中的字段重命名为实体类的属性
column 数据库中字段名
property POJO属性名
javaType POJO类型
jdbcType 数据库字段类型
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
<property name="useActualColumnNames" value="true"/>
<generatedKey column="ID" sqlStatement="DB2" identity="true" />
<columnOverride column="DATE_FIELD" property="startDate" />
<ignoreColumn column="FRED" />
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
</table>
<columnRenamingRule>
按规则将数据库中的字段重命名为实体类的属性
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
<columnRenamingRule searchString="^CUST_" replaceString="" />
..
</table>
<commentGenerator>
代码上面的注释规则
子属性:property
porperties:
suppressAllComments false时打开注释,true时关闭注释
suppressDate false时打开时间标志,true时关闭...真是反人类啊
<commentGenerator> <property name="suppressDate" value="true" /> </commentGenerator>
<context>
这个实在不知道怎么解释,反正就是大环境
targetRuntime 可选项,可填值为MyBatis3,MyBatis3Simple(默认的),Ibatis2Java2,Ibatis2Java5
<context id="DB2Tables" targetRuntime="MyBatis3"> ... </context>
<generatedKey>
指定自增加以及Id
column 字段
sqlStatement 数据库语句,可以为MySql,DB2,SqlServer,SyBase等http://mybatis.github.io/generator/configreference/generatedKey.html
identity true为id,false不为id
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" > <property name="useActualColumnNames" value="true"/> <generatedKey column="ID" sqlStatement="DB2" identity="true" /> <columnOverride column="DATE_FIELD" property="startDate" /> <ignoreColumn column="FRED" /> <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> </table>
<ignoreColumn>
忽略字段
column 字段名
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" > <ignoreColumn column="FRED" />
.. </table>
<javaClientGenerator>
Mapper生成配置
type XMLMAPPER配置文件方式,ANNOTATEDMAPPER注解方式
http://mybatis.github.io/generator/configreference/javaClientGenerator.html
<javaClientGenerator type="XMLMAPPER" targetPackage="dao.mapper" targetProject="app"> <property name="enableSubPackages" value="true" /> </javaClientGenerator>
<javaModelGenerator>
实体类生成配置
http://mybatis.github.io/generator/configreference/javaModelGenerator.html
<javaModelGenerator targetPackage="domain" targetProject="app"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="false" /> </javaModelGenerator>
<javaTypeResolver>
mybatis里专门用来处理NUMERIC和DECIMAL类型的策略
<javaTypeResolver> <property name="forceBigDecimals" value="true" /> </javaTypeResolver>
<jdbcConnection>
jdbc配置,不解释了哈
<jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver" connectionURL="jdbc:db2:MBGTEST" userId="db2admin" password="db2admin"> </jdbcConnection>
<sqlMapGenerator>
生成sql语句的xml文件
在mybatis2里是必须的,在mybatis3中,只有用XML方式的时候才是需要的。
<sqlMapGenerator targetPackage="test.model" targetProject="\MyProject\src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator>