mybatis自動產生dao, model, mapper xml檔案

來源:互聯網
上載者:User

標籤:art   映射   enables   nodename   als   model   jar   自動   nbsp   

用mybatis的時候,手寫xml或model檔案是一個力氣活,所以可以用mybatis-gennerator外掛程式自動產生mybatis所需要的dao、bean、mapper xml檔案

(原文地址:http://blog.csdn.net/tolcf/article/details/50835165)

附件:http://files.cnblogs.com/files/cc-robot/generator.rar

把附件解壓到本地,我放在d:\web\java目錄下了

只需要修改下面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="D:\web\java\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/dbname?characterEncoding=utf8" userId="dbuser" password="dbpass"> 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.callservice.model" targetProject="D:\web\java\generator\src">20             <property name="enableSubPackages" value="true" />21             <property name="trimStrings" value="true" />22         </javaModelGenerator>23         <!-- 產生的對應檔包名和位置 -->24         <sqlMapGenerator targetPackage="com.callservice.mapping" targetProject="D:\web\java\generator\src">25             <property name="enableSubPackages" value="true" />26         </sqlMapGenerator>27         <!-- 產生DAO的包名和位置 -->28         <javaClientGenerator type="XMLMAPPER" targetPackage="com.callservice.dao" targetProject="D:\web\java\generator\src">29             <property name="enableSubPackages" value="true" />30         </javaClientGenerator>31         <!-- 要產生那些表(更改tableName和domainObjectName就可以) -->32         <table tableName="admin" domainObjectName="admin" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />33         <!-- <table tableName="course_info" domainObjectName="CourseInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />34         <table tableName="course_user_info" domainObjectName="CourseUserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> -->35     </context>36 </generatorConfiguration>

 然後windwos下開啟命令列模式,切換到generator目錄下,執行:

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

 出現successfully,證明產生成功了。

這時再切換到generator/src目錄下,可以看到剛才產生的檔案了,有三個檔案夾:dao,mapping,model,把產生的檔案複製到相應項目目錄下就可以了。

mybatis自動產生dao, model, mapper xml檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.