Mybatis Generator 配置详解

<?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>

  <!--导入属性配置-->
  <properties resource="generator/generatorConfig.properties"/>

  <!-- 数据库驱动:换成你本地的驱动包位置-->
  <classPathEntry location="${mysql.connector.jar.path}"/>

  <!-- context 是逆向工程的主要配置信息 -->
  <!-- id:名字 -->
  <!-- targetRuntime:设置生成的文件适用于 mybatis 版本 -->
  <context id="default" targetRuntime="MyBatis3">

    <!--optional,旨在创建class时,对注释进行控制-->
    <commentGenerator>
      <property name="suppressDate" value="true"/>
      <!-- 是否去除自动生成的注释 true:是 : false:否 -->
      <property name="suppressAllComments" value="true"/>
    </commentGenerator>

    <!--数据库链接URL,用户名、密码 -->
    <jdbcConnection driverClass="${generator.driver.class}"
      connectionURL="${generator.conn.url}" userId="${generator.user}"
      password="${generator.pass}">
    </jdbcConnection>

    <!--非必须,类型处理器,在数据库类型和java类型之间的转换控制-->
    <javaTypeResolver>
      <!-- 默认情况下数据库中的 decimal,bigInt 在 Java 对应是 sql 下的 BigDecimal 类 -->
      <!-- 不是 double 和 long 类型 -->
      <!-- 使用常用的基本类型代替 sql 包下的引用类型 -->
      <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>

    <!-- targetPackage:生成的实体类所在的包 -->
    <!-- targetProject:生成的实体类所在的硬盘位置 -->
    <javaModelGenerator targetPackage="com.jd.jbdp.integrate.common.generator.entity"
      targetProject="src/main/java">
      <!-- 是否允许子包 -->
      <property name="enableSubPackages" value="true"/>
      <!-- 是否对modal添加构造函数 -->
      <property name="constructorBased" value="true" />
      <!-- 是否清理从数据库中查询出的字符串左右两边的空白字符 -->
      <property name="trimStrings" value="true" />
      <!-- 建立modal对象是否不可改变 即生成的modal对象不会有setter方法,只有构造方法 -->
      <property name="immutable" value="false" />
    </javaModelGenerator>

    <!-- 生成映射文件的包名和位置-->
    <sqlMapGenerator targetPackage="resources.mapper" targetProject="src/main">
      <!-- 针对数据库的一个配置,是否把 schema 作为字包名 -->
      <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>

    <!-- 生成DAO的包名和位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.jd.jbdp.integrate.common.generator.dao"
      targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>

    <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
    <table tableName="integrate_ds_info" domainObjectName="SyncDbTask" enableCountByExample="false"
      enableUpdateByExample="false"
      enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  </context>
</generatorConfiguration>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容