自動生成ibatis檔案及mybatis檔案的方法
generatorConfig - mybatis:
<?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>
<context id="DB2Tables" targetRuntime="MyBatis3">
<!--去除註釋 (true好像不起作用) -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--資料庫連線 -->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@192.168.1.1:1521:testdb"
userId="tingke"
password="tingke">
</jdbcConnection>
<!--預設false
Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC.
-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成實體類 指定包名 以及生成的地址 (可以自定義地址,但是路徑不存在不會自動建立 使用Maven生成在target目錄下,會自動建立) -->
<javaModelGenerator targetPackage="com.tingke.model" targetProject="E:\01soft_green">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成對映(XML實現)檔案的包名和位置; 注意多次生成後文件內會有重複,請自己解決 -->
<sqlMapGenerator targetPackage="com.tingke.mybatis" targetProject="E:\01soft_green">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成DAO(Java介面檔案)的包名和位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.tingke.dao.mapper"
targetProject="E:\01soft_green">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table tableName="ELITE_PK_VOTE_TEN_INFO" domainObjectName="ElitePkVoteTenInfo"/>
<table tableName="ELITE_PK_VOTE_TEN_LOGS" domainObjectName="ElitePkVoteTenLogs"/>
<!--處理結束-->
</context>
</generatorConfiguration>
generatorConfig - ibatis:
<?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>
<context id="DB2Tables" targetRuntime="Ibatis2Java5">
<!--去除註釋 (true好像不起作用) -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--資料庫連線 -->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@192.168.1.1:1521:testdb"
userId="tingke"
password="tingke">
</jdbcConnection>
<!--預設false
Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC.
-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成實體類 指定包名 以及生成的地址 (可以自定義地址,但是路徑不存在不會自動建立 使用Maven生成在target目錄下,會自動建立) -->
<javaModelGenerator targetPackage="com.tingke.model" targetProject="E:\01soft_green">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成對映(XML實現)檔案的包名和位置; 注意多次生成後文件內會有重複,請自己解決 -->
<sqlMapGenerator targetPackage="com.tingke.mybatis" targetProject="E:\01soft_green">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成DAO(Java介面檔案)的包名和位置-->
<javaClientGenerator type="SPRING" targetPackage="com.tingke.dao.mapper"
targetProject="E:\01soft_green">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table tableName="ELITE_PK_VOTE_TEN_INFO" domainObjectName="ElitePkVoteTenInfo"/>
<table tableName="ELITE_PK_VOTE_TEN_LOGS" domainObjectName="ElitePkVoteTenLogs"/>
<!--處理結束-->
</context>
</generatorConfiguration>
其實很簡單,只有兩個地方不一樣: