1. 程式人生 > >使用mybatis-generator-core生成MyBatis Mapper檔案

使用mybatis-generator-core生成MyBatis Mapper檔案

1 下載 mybatis-generator-core-1.3.5

2 解壓到 d:\

3 配置 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="D:\mysql-connector-java-5.1.26\mysql-connector-java-5.1.26-bin.jar" />
  <context id="context1" >
  	<!-- 去掉註釋 -->
		<commentGenerator>
			<property name="suppressAllComments" value="true" />
			<property name="suppressDate" value="true" />
		</commentGenerator>
     <jdbcConnection driverClass="com.mysql.jdbc.Driver"  connectionURL="jdbc:mysql://192.168.20.162:3306/tsb_ischool_qingguo?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true" userId="資料庫使用者" password="資料庫密碼" /> 
    <!-- 禁止型別強制轉換 -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<!-- 生成bean類存放位置 -->
		<javaModelGenerator targetPackage="com.tsb.ischool.oauth2.bean"
			targetProject="D:\work\專案名\src\main\java">
		</javaModelGenerator>
		<!-- 生成mapper檔案存放位置 -->
		<sqlMapGenerator targetPackage="com.tsb.ischool.oauth2.mapper"
			targetProject="D:\work\專案名\src\main\java">
		</sqlMapGenerator>
		<!-- 生成Dao類存放位置 -->
		<javaClientGenerator targetPackage="com.tsb.ischool.oauth2.dao" 
		type="XMLMAPPER" targetProject="D:\work\專案名\src\main\java">
		</javaClientGenerator>
		<table tableName="t_oauth_token" domainObjectName="TokenBean" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"> 
		<property name="useActualColumnNames" value="false" />
		</table>
		<table tableName="t_oauth_app" domainObjectName="AppBean"  enableCountByExample="true" enableUpdateByExample="true"
 enableDeleteByExample="true" 
 enableSelectByExample="true" selectByExampleQueryId="true">
 <property name="useActualColumnNames" value="false" />
 </table>
 <table tableName="t_oauth_app_ext" domainObjectName="AppExtBean" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
 <property name="useActualColumnNames" value="false" />
 </table>
 </context>
</generatorConfiguration>
4 將 mybatis-generator-core-1.3.5.jar 放到  D:\work\專案名\mybatis-generator-core-1.3.5.jar (不支援 jdk1.8,必須 1.7) 5 windows下使用命令提示進入工作目錄: cd D:\work\TSB_ISCHOOL2_SERVICE_OAUTH2
6 在命令提示符下執行  java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml -overwrite

7 mapper檔案就會生成在上述 xml指定的路徑,手工開啟檢視並再次編輯即可使用