MyBatis Generator XML 配置


使用反向生成器可以生成數據庫表對應的實體類和mapper映射文件:

以下是具體介紹相應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 >
  <classPathEntry location="D:/DMCworkspace/z_DMC/src/mysql-connector-java-5.1.7-bin.jar" /> //用於指定加載內省數據庫驅動的路徑
  <context id="aim-generator-mybatis3" defaultModelType="flat">   //defaultModelType指定如何生成實體類,flat:該模型為每一張表只生成一個實體類。這個實體類包含表中的所有字段
    <property name="beginningDelimiter" value="`"/>
    <property name="endingDelimiter" value="`"/>
    <property name="javaFileEncoding" value="UTF-8"/>
	<commentGenerator>
	    <property name="suppressAllComments" value="false"/>
	    <property name="suppressDate" value="true"/>
	</commentGenerator>  	
  	
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.17.11:3306/dmc" userId="dmc" password="dmc">
    </jdbcConnection>	//加載驅動
    
    <javaModelGenerator targetPackage="bz.sunlight.dmcEntity" targetProject="z_DMC">
    	<property name="trimStrings" value="true" />  //trimStrings:是否對數據庫查詢結果進行trim操作,如果設置為true就會生成類似這樣public void setUsername(String username) {this.username = username == null ? null : username.trim();}的setter方法。默認值為false。
   	</javaModelGenerator>
   	
   	
    
    <sqlMapGenerator targetPackage="bz.sunlight.dao" targetProject="z_DMC">
    </sqlMapGenerator>	
    
    <javaClientGenerator targetPackage="bz.sunlight.dao" targetProject="z_DMC" type="XMLMAPPER">
    	<property name="exampleMethodVisibility" value="public" />
    </javaClientGenerator>	
    
    <table schema="dmc" tableName="vehicle_list"> //tableName:指定要生成的表名,可以使用SQL通配符匹配多個表。生成所有的表可以這樣設置<table tableName="%" />,可以指定的表明生成指定的實體類和映射
    </table>
    <!--
    <table schema="dmc" tableName="vehicle" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
      enableSelectByExample="false" selectByExampleQueryId="false">
      <columnOverride column="Id" property="id" />
    </table>
    -->
  </context>
</generatorConfiguration>
 
         

  

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM