mybatis自動生成程式碼generator
阿新 • • 發佈:2018-11-08
mybatis-generator-core-1.3.2.jar包
編寫genertor的xml檔案,名下:generator.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 >
<!-- 資料庫的JDBC驅動的jar包地址-->
<classPathEntry location="D:\mysql-connector-java-5.1.13-bin.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自動生成的註釋 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
<!--資料庫連線的資訊:驅動類、連線地址、使用者名稱、密碼 -->
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="root" />
<!-- 預設false,把JDBC DECIMAL 和 NUMERIC 型別解析為 Integer
true,把JDBC DECIMAL 和 NUMERIC 型別解析為java.math.BigDecimal
-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 自動生成程式碼的包名和位置,targetProject可以寫絕對路徑也可以寫專案名 -->
<javaModelGenerator targetPackage="com.test.model" targetProject="E:\eclipse\workspace\ssm\src">
<!-- 是否讓schema作為包的字尾 -->
<property name="enableSubPackages" value="true" />
<!-- 生成的對映檔案報名和位置 -->
<sqlMapGenerator targetPackage="com.test.mapper" targetProject="ssm" />
<!-- 生成DAO的包名和位置 -->
<javaClientGenerator targetPackage="com.test.mapper" targetProject="ssm" type="XMLMAPPER" />
<!-- 從資料庫返回的值被清理前後的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- domainObjectName是表對應的實體類名, tableName是對應的表名-->
<!-- table可以配置多個,enable*幾個引數是為了自動生成一些額外的sql操作,可以關閉-->
<!--
schema即為資料庫名, tableName為對應的資料庫表, domainObjectName是要生成的實體類,
如果想要mapper配置檔案加入sql的where條件查詢, 可以將enableCountByExample等設為true,
這樣就會生成一個對應domainObjectName的Example類, enableCountByExample等設為false時,
就不會生成對應的Example類了.
如果table裡邊不配置property,預設欄位都生成為類屬性。
<ignoreColumn column="FRED" />//忽略欄位
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />//無論欄位是什麼型別,生成的類屬性都是varchar。 -->
<table schema="test" tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>