1. 程式人生 > >mybatis-generator命令列生成程式碼

mybatis-generator命令列生成程式碼

目錄檔案如下:

generator.xml檔案如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 3 <generatorConfiguration>
 4     <!-- 資料庫驅動包位置 -->
5 <classPathEntry location="E:\generator\mysql-connector-java-5.1.34.jar" /> 6 <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />--> 7 <context id="DB2Tables" targetRuntime="MyBatis3"> 8 <commentGenerator> 9 <
property name="suppressAllComments" value="true" /> 10 </commentGenerator> 11 <!-- 資料庫連結URL、使用者名稱、密碼 --> 12 <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/new_taozugong" userId="root" password="root"> 13 <!--
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">--> 14 </jdbcConnection> 15 <javaTypeResolver> 16 <property name="forceBigDecimals" value="false" /> 17 </javaTypeResolver> 18 <!-- 生成模型的包名和位置 --> 19 <javaModelGenerator targetPackage="com.taozugong.admin.common.entity" targetProject="E:\generator\src"> 20 <property name="enableSubPackages" value="true" /> 21 <property name="trimStrings" value="true" /> 22 </javaModelGenerator> 23 <!-- 生成的對映檔案包名和位置 --> 24 <sqlMapGenerator targetPackage="mybatis.mapper" targetProject="E:\generator\src"> 25 <property name="enableSubPackages" value="true" /> 26 </sqlMapGenerator> 27 <!-- 生成DAO的包名和位置 --> 28 <javaClientGenerator type="XMLMAPPER" targetPackage="com.taozugong.admin.dao.mapper" targetProject="E:\generator\src"> 29 <property name="enableSubPackages" value="true" /> 30 </javaClientGenerator> 31 <!-- 要生成那些表(更改tableName和domainObjectName就可以) --> 32 33 <table tableName="activity" domainObjectName="Activity" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 34 <table tableName="activity_help_record" domainObjectName="activityHelpRecord" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 35 <table tableName="activity_product_setting" domainObjectName="activityProductSetting" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 36 <table tableName="activity_product_template" domainObjectName="activityProductTemplate" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 37 <table tableName="activity_record" domainObjectName="activityRecord" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 38 </context> 39 40 </generatorConfiguration>

直接cmd輸入如下命令即可生成

java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite