mybatis generator 配置文件介绍

一、init.properties 文件内容:

classPath=C:\\repository\\mysql\\mysql-connector-java\\8.0.18\\mysql-connector-java-8.0.18.jar

jdbc_driver=com.mysql.cj.jdbc.Driver
jdbc_url=jdbc:mysql://127.0.0.1:3306/fhm_test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&serverTimezone=Asia/Shanghai&connectTimeout=600000&socketTimeout=600000&useSSL=true
jdbc_user=root
jdbc_password=123456

domain_package=com.example.test.domain
xml_package=com.example.test.mapper
dao_package=com.example.test.mapper

table=user
domain=User

二、generatorConfig.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>
    <!-- 引入配置文件 -->
    <properties resource="init.properties"/>

    <!-- 指定数据连接驱动jar地址 -->
    <classPathEntry location="${classPath}"/>

    <!-- 一个数据库一个context -->
    <context id="context1">
        <!-- 注释 -->
        <commentGenerator>
            <!-- 是否取消注释 -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!-- jdbc连接 -->
        <jdbcConnection driverClass="${jdbc_driver}"
                        connectionURL="${jdbc_url}" userId="${jdbc_user}"
                        password="${jdbc_password}">
            <!-- 设置为true,则xxHost 和 xxWithBLOBs等多余的信息就不会生成 -->
            <property name="nullCatalogMeansCurrent" value="true"/>
        </jdbcConnection>

        <!-- 类型转换 -->
        <javaTypeResolver>
            <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- 生成实体类地址 -->
        <javaModelGenerator targetPackage="${domain_package}"
                            targetProject="src/main/java">
            <!-- 是否在当前路径下新加一层schema,eg:fase:路径 com.example.test.domain, true: com.example.test.domain.[schemaName] -->
            <property name="enableSubPackages" value="true"/>
            <!-- 是否针对string类型的字段在set的时候进行trim调用 -->
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- 生成mapxml文件 -->
        <sqlMapGenerator targetPackage="${xml_package}"
                         targetProject="src/main/resources">
            <!-- 是否在当前路径下新加一层schema,eg:fase:路径 com.example.test.domain, true: com.example.test.domain.[schemaName] -->
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!--生成mapxml对应client,也就是接口dao -->
        <javaClientGenerator targetPackage="${dao_package}"
                             targetProject="src/main/java" type="XMLMAPPER">
            <!-- 是否在当前路径下新加一层schema,eg:fase:路径 com.example.test.domain, true: com.example.test.domain.[schemaName] -->
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <!-- 配置表信息 -->
        <table tableName="${table}" domainObjectName="${domain}"
               enableCountByExample="true"
               enableDeleteByExample="true"
               enableSelectByExample="true"
               enableUpdateByExample="true">
            <columnOverride column="age" javaType="java.lang.Integer" jdbcType="TINYINT"/>
        </table>
        
    </context>

</generatorConfiguration>

数据库信息:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值