日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件

發布時間:2023/12/13 java 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

具體請參照:

http://blog.csdn.net/fengshizty/article/details/43086833

按照上面博客地址,下載Generator的依賴包:

如下是我的配置文件:

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="C:\Generate\generator\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://localhost:3306/testmybatis" userId="root" password="XXXXX"> 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.zlg.model" targetProject="C:\Generate\generator\generator\src"> 20 <property name="enableSubPackages" value="true" /> 21 <property name="trimStrings" value="true" /> 22 </javaModelGenerator> 23 <!-- 生成的映射文件包名和位置 --> 24 <sqlMapGenerator targetPackage="com.zlg.mapping" targetProject="C:\Generate\generator\generator\src"> 25 <property name="enableSubPackages" value="true" /> 26 </sqlMapGenerator> 27 <!-- 生成DAO的包名和位置 --> 28 <javaClientGenerator type="XMLMAPPER" targetPackage="com.zlg.dao" targetProject="C:\Generate\generator\generator\src"> 29 <property name="enableSubPackages" value="true" /> 30 </javaClientGenerator> 31 <!-- 要生成那些表(更改tableName和domainObjectName就可以) --> 32 <table tableName="user" domainObjectName="UserInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 33 <table tableName="dept" domainObjectName="DeptInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 34 <table tableName="emp" domainObjectName="EmpInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 35 <table tableName="cost" domainObjectName="CostInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> 36 </context> 37 </generatorConfiguration> View Code

根據以上配置文件中的標記位置,修改成你需要的位置,然后運行如下指令(記住用tab鍵補全命令,這個用過CMD或者Linux都知道)。

運行成功后,就生成了如下文件:

當然,如果你比較懶,可以直接把生成路徑設置成你項目的相應位置。

?

此時,你就可以把這些對應的文件拷貝到項目的相關位置了。非常簡單,而且以上鏈接的作者已經寫得很詳細了。

感謝分享~

轉載于:https://www.cnblogs.com/flydkPocketMagic/p/5998478.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的【Java MyBatis Generator】使用generator自动生成Dao,Mapping和实体文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。