MyBatis Generator generatorConfig.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.     <properties resource="init.properties"/>  
  6.       
  7.     <!-- 指定数据链接驱动jar地址 -->  
  8.     <classPathEntry location="${classPath}" />  
  9.       
  10.     <!-- 一个数据库一个context -->  
  11.     <context id="infoGuardian">  
  12.         <!-- 注释 -->  
  13.         <commentGenerator >  
  14.             <property name="suppressAllComments" value="false"/><!-- 是否取消注释 -->  
  15.             <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳-->  
  16.         </commentGenerator>  
  17.           
  18.         <!-- jdbc链接 -->  
  19.         <jdbcConnection driverClass="${jdbc_driver}"  
  20.             connectionURL="${jdbc_url}" userId="${jdbc_user}"  
  21.             password="${jdbc_password}" />  
  22.           
  23.         <!-- 类型转换 -->  
  24.         <javaTypeResolver>  
  25.             <!-- 是否使用bigDecimal, false可自动转化如下类型(Long, Integer, Short, etc.) -->  
  26.             <property name="forceBigDecimals" value="false"/>  
  27.         </javaTypeResolver>  
  28.           
  29.         <!-- 生成实体类地址 -->    
  30.         <javaModelGenerator targetPackage="com.oop.eksp.user.model"  
  31.             targetProject="${project}" >  
  32.             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
  33.             <property name="enableSubPackages" value="false"/>  
  34.             <!-- 是否针对string类型的字段在set的时候进行trim调用 -->  
  35.             <property name="trimStrings" value="true"/>  
  36.         </javaModelGenerator>  
  37.           
  38.         <!-- 生成mapxml文件 -->  
  39.         <sqlMapGenerator targetPackage="com.oop.eksp.user.data"  
  40.             targetProject="${project}" >  
  41.             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
  42.             <property name="enableSubPackages" value="false" />  
  43.         </sqlMapGenerator>  
  44.           
  45.         <!-- 生成mapxml对应client,也就是接口dao -->      
  46.         <javaClientGenerator targetPackage="com.oop.eksp.user.data"  
  47.             targetProject="${project}" type="XMLMAPPER" >  
  48.             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
  49.             <property name="enableSubPackages" value="false" />  
  50.         </javaClientGenerator>  
  51.           
  52.         <!-- 配置表信息 -->      
  53.         <table schema="${jdbc_user}" tableName="s_user"  
  54.             domainObjectName="UserEntity" enableCountByExample="false"  
  55.             enableDeleteByExample="false" enableSelectByExample="false"  
  56.             enableUpdateByExample="false">  
  57.             <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample   
  58.                 是否生成 example类   -->  
  59.               
  60.             <!-- 忽略列,不生成bean 字段 -->  
  61.             <ignoreColumn column="FRED" />  
  62.             <!-- 指定列的java数据类型 -->  
  63.             <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />  
  64.         </table>  
  65.   
  66.     </context>  
  67. </generatorConfiguration>  
  68. 附带上个人init.properties
  69. #Mybatis Generator configuration  
  70. project = EKSP  
  71. classPath=E:/workplace/EKSP/WebContent/WEB-INF/lib/ojdbc14.jar  
  72. jdbc_driver = oracle.jdbc.driver.OracleDriver  
  73. jdbc_url=jdbc:oracle:thin:@127.0.0.1:1521:orcl  
  74. jdbc_user=INFOGUARDIAN  
  75. jdbc_password=info_idap132