欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MyBatis-Generator的配置說明和使用

 更新時間:2017年02月04日 09:56:10   作者:hnlictmso  
本文主要介紹了MyBatis-Generator的配置說明和使用的相關(guān)知識。具有很好的參考價值,下面跟著小編一起來看下吧

關(guān)于MyBatis:

MyBatis Generator (MBG) 是一個Mybatis的代碼生成器 MyBatis 和 iBATIS. 他可以生成Mybatis各個版本的代碼,和iBATIS 2.2.0版本以后的代碼。 他可以內(nèi)省數(shù)據(jù)庫的表(或多個表)然后生成可以用來訪問(多個)表的基礎對象。 這樣和數(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ù)庫中對應的表:  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目錄下就會生成 對應的接口、映射文件和實體類

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

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論