mybatis利用maven自動產生mapper、xml、domain

來源:互聯網
上載者:User

標籤:

第一種方式:配置maven外掛程式
在src/main/resources下建立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> 
<context id="sqlserverTables" targetRuntime="MyBatis3"> 
<!-- 產生的pojo,將implements Serializable--> 
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> 
<commentGenerator> 
<!-- 是否去除自動產生的注釋 true:是 : false:否 --> 
<property name="suppressAllComments" value="true" /> 
</commentGenerator> 

<!-- 資料庫連結URL、使用者名稱、密碼 --> 
<jdbcConnection driverClass="com.mysql.jdbc.Driver" 
connectionURL="jdbc:mysql://127.0.0.1:3306/thinkphp?useUnicode=true&amp;characterEncoding=UTF-8" 
userId="root" 
password="root"> 
</jdbcConnection> 

<!-- 預設false,把JDBC DECIMAL 和 NUMERIC 類型解析為 Integer 
true,把JDBC DECIMAL 和 NUMERIC 類型解析為java.math.BigDecimal 
--> 
<javaTypeResolver> 
<property name="forceBigDecimals" value="false" /> 
</javaTypeResolver> 

<!-- 產生model模型,對應的包路徑,以及檔案存放路徑(targetProject),targetProject可以指定具體的路徑,如./src/main/java, 
也可以使用“MAVEN”來自動產生,這樣產生的程式碼會在target/generatord-source目錄下 
--> 
<!--<javaModelGenerator targetPackage="com.joey.mybaties.test.pojo" targetProject="MAVEN">--> 
<javaModelGenerator targetPackage="com.kongzhong.gw2.ccc.mapper" targetProject="./src/main/java"> 
<property name="enableSubPackages" value="true"/> 
<!-- 從資料庫返回的值被清理前後的空格 --> 
<property name="trimStrings" value="true" /> 
</javaModelGenerator> 

<!--對應的mapper.xml檔案 --> 
<sqlMapGenerator targetPackage="com.kongzhong.gw2.ccc.mapper" targetProject="./src/main/resources"> 
<property name="enableSubPackages" value="true"/> 
</sqlMapGenerator> 

<!-- 對應的Mapper介面類檔案 --> 
<javaClientGenerator type="XMLMAPPER" targetPackage="com.kongzhong.gw2.ccc.mapper" targetProject="./src/main/java"> 
<property name="enableSubPackages" value="true"/> 
</javaClientGenerator> 


<!-- 列出要產生代碼的所有表,這裡配置的是不產生Example檔案 --> 
<table tableName="tp_user" domainObjectName="User" 
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" 
enableSelectByExample="false" selectByExampleQueryId="false" > 
<property name="useActualColumnNames" value="false"/> 
</table> 

</context> 
</generatorConfiguration>    執行maven命令:mybatis-generator:generate  第二種方式:  maven外掛程式    <plugin>
           <groupId>org.mybatis.generator</groupId>
           <artifactId>mybatis-generator-maven-plugin</artifactId>
           <version>1.3.0</version>
           <dependencies>
               <dependency>
                  <groupId>mysql</groupId>
                  <artifactId>mysql-connector-java</artifactId>
                  <version>5.1.34</version>
               </dependency>
           </dependencies>
           <configuration>
                 <overwrite>true</overwrite>
            </configuration>
         </plugin>在src/main/resources下建立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>
<context id="mysqlgenerator" targetRuntime="MyBatis3">
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://10.230.10.27:3306/gw2_dianquan?useUnicode=true&amp;characterEncoding=UTF-8" 
userId="hongdian"
password="123456" />
<javaModelGenerator targetPackage="com.kongzhong.gw2.onepercentbg.domain" targetProject="src\main\java" />
<sqlMapGenerator targetPackage="com.kongzhong.gw2.onepercentbg.mapper" targetProject="src\main\resources" />
<javaClientGenerator type="XMLMAPPER" targetPackage="com.kongzhong.gw2.onepercentbg.mapper" targetProject="src\main\java" />
<table tableName="t_yizhestore_item" domainObjectName="Items"/>
</context> 
</generatorConfiguration>  執行maven命令:mybatis-generator:generate

mybatis利用maven自動產生mapper、xml、domain

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.