国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

MyBatis-Generator的配置說明和使用

2019-11-26 13:09:23
字體:
供稿:網(wǎng)友

關(guān)于MyBatis:

MyBatis Generator (MBG) 是一個Mybatis的代碼生成器 MyBatis 和 iBATIS. 他可以生成Mybatis各個版本的代碼,和iBATIS 2.2.0版本以后的代碼。 他可以內(nèi)省數(shù)據(jù)庫的表(或多個表)然后生成可以用來訪問(多個)表的基礎(chǔ)對象。 這樣和數(shù)據(jù)庫表進行交互時不需要創(chuàng)建對象和配置文件。 MBG的解決了對數(shù)據(jù)庫操作有最大影響的一些簡單的CRUD(插入,查詢,更新,刪除)操作。

準備工作:

下載MyBatis-Generator 點擊此處下載

下載成功以后 如下圖

generatorConfig.xml是核心配置文件,主要內(nèi)容與解釋如下

<?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> <!--   在此處修改數(shù)據(jù)庫的驅(qū)動包 必須提前將驅(qū)動包放到本配置文件的同級目錄下 筆者已提前放好  如使用Oracle數(shù)據(jù)庫時 <classPathEntry location="oracle.jar" /> --> <classPathEntry location="mysql.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3">  <commentGenerator>   <property name="suppressAllComments" value="true" />   <!-- 是否取消注釋 -->   <property name="suppressDate" value="true" />    <!-- 是否生成注釋代時間戳 -->  </commentGenerator>  <!-- 此處修改數(shù)據(jù)庫的連接信息 -->  <jdbcConnection driverClass="com.mysql.jdbc.Driver"   connectionURL="jdbc:mysql://localhost:3306/easybuy" userId="root"   password="pengxiongpengdi" />  <javaTypeResolver>   <property name="forceBigDecimals" value="false" />  </javaTypeResolver>  <!--    要生成的實體類   每個項目包的命名 都不一樣 可以通過修改 該屬性 實現(xiàn)   targetPackage="com.buy.entity"   -->  <javaModelGenerator targetPackage="com.buy.entity"   targetProject="src">   <property name="enableSubPackages" value="true" />   <property name="trimStrings" value="true" />  </javaModelGenerator>  <!-- 要生成的接口 -->  <sqlMapGenerator targetPackage="com.buy.dao"   targetProject="src">   <property name="enableSubPackages" value="true" />  </sqlMapGenerator>  <!-- 要生成的映射文件 -->  <javaClientGenerator type="XMLMAPPER"   targetPackage="com.buy.dao" targetProject="src">   <property name="enableSubPackages" value="true" />  </javaClientGenerator>  <!--    配置要映射的表   數(shù)據(jù)庫中對應(yīng)的表:  tableName="EASYBUY_PRODUCT"    項目中實體類的名字: domainObjectName="ProductEntity"   其他屬性默認即可  -->  <table tableName="EASYBUY_PRODUCT" domainObjectName="ProductEntity"    enableCountByExample="false" enableUpdateByExample="false"   enableDeleteByExample="false" enableSelectByExample="false"   selectByExampleQueryId="false"></table>  <table tableName="EASYBUY_PRODUCT_CATEGORY" domainObjectName="CategoryEntity"   enableCountByExample="false" enableUpdateByExample="false"   enableDeleteByExample="false" enableSelectByExample="false"   selectByExampleQueryId="false"></table>  <table tableName="EASYBUY_USER" domainObjectName="UserEntity"   enableCountByExample="false" enableUpdateByExample="false"   enableDeleteByExample="false" enableSelectByExample="false"   selectByExampleQueryId="false"></table> </context></generatorConfiguration>

配置好以后運行g(shù)o.cmd  src目錄下就會生成 對應(yīng)的接口、映射文件和實體類

此時就生成完畢了可以在此基礎(chǔ)上添加其他功能

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持武林網(wǎng)!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 博乐市| 前郭尔| 台东县| 纳雍县| 泸定县| 安泽县| 吉木萨尔县| 奉贤区| 德州市| 盘锦市| 上饶市| 建始县| 安新县| 汝州市| 讷河市| 墨脱县| 揭阳市| 金昌市| 察哈| 台山市| 白玉县| 临沭县| 贵州省| 林口县| 张家川| 永康市| 如东县| 玛曲县| 出国| 阳春市| 石楼县| 绥宁县| 尼玛县| 曲沃县| 西城区| 九江市| 望江县| 高碑店市| 出国| 京山县| 大同县|