驅動文件指定配置項html
<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />
將數據庫中的字段重命名爲實體類的屬性java
column 數據庫中字段名git
property POJO屬性名github
javaType POJO類型sql
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>
按規則將數據庫中的字段重命名爲實體類的屬性mybatis
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
<columnRenamingRule searchString="^CUST_" replaceString="" />
..
</table>
代碼上面的註釋規則app
子屬性:propertydom
suppressAllComments false時打開註釋,true時關閉註釋ide
suppressDate false時打開時間標誌,true時關閉...真是反人類啊
<commentGenerator> <property name="suppressDate" value="true" /> </commentGenerator>
這個實在不知道怎麼解釋,反正就是大環境
targetRuntime 可選項,可填值爲MyBatis3,MyBatis3Simple(默認的),Ibatis2Java2,Ibatis2Java5
<context id="DB2Tables" targetRuntime="MyBatis3"> ... </context>
指定自增長以及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>
忽略字段
column 字段名
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" > <ignoreColumn column="FRED" />
.. </table>
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>
實體類生成配置
http://mybatis.github.io/generator/configreference/javaModelGenerator.html
<javaModelGenerator targetPackage="domain" targetProject="app"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="false" /> </javaModelGenerator>
mybatis裏專門用來處理NUMERIC和DECIMAL類型的策略
<javaTypeResolver> <property name="forceBigDecimals" value="true" /> </javaTypeResolver>
jdbc配置,不解釋了哈
<jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver" connectionURL="jdbc:db2:MBGTEST" userId="db2admin" password="db2admin"> </jdbcConnection>
生成sql語句的xml文件
在mybatis2裏是必須的,在mybatis3中,只有用XML方式的時候纔是須要的。
<sqlMapGenerator targetPackage="test.model" targetProject="\MyProject\src"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator>