MyBatis Generator generatorConfig.xml配置详解

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