MyBatis自动生成代码之generatorConfig配置文件及其详细解读

<?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="jdbc.properties"/>  
      
    <!-- 指定数据连接驱动jar地址 -->  
    <classPathEntry location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" />  
      
    <!-- 一个数据库一个context -->  
    <context id="FCRMTables">  
        <!-- 注释 -->  
        <commentGenerator >  
            <property name="suppressAllComments" value="true"/><!-- 是否取消注释 -->  
            <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳-->  
        </commentGenerator>  
          
        <!-- jdbc连接 -->  
        <jdbcConnection driverClass="${driverClassName}"  
            connectionURL="${url}" userId="${username}"  
            password="${password}" />  
          
        <!-- 类型转换 -->  
        <javaTypeResolver>  
            <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->  
            <property name="forceBigDecimals" value="false"/>  
        </javaTypeResolver>  
          
        <!-- 生成实体类的包名和位置 注意targetProject的值为实体类放在工程中具体位置的相对路径,-->  
        <javaModelGenerator targetPackage="com.qlm.entity"  
            targetProject="src/main/java" >  
            <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
            <property name="enableSubPackages" value="true"/>  
            <!-- 是否针对string类型的字段在set的时候进行trim调用 -->  
            <property name="trimStrings" value="true"/>  
        </javaModelGenerator>  
          
        <!-- 生成的SQLMapper映射文件包名和位置 -->  
        <sqlMapGenerator targetPackage="mybatisMapper"  
            targetProject="src/main/resources" >  
            <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
            <property name="enableSubPackages" value="true" />  
        </sqlMapGenerator>  
          
        <!-- 生成DAO的包名和位置,这里配置将生成的dao类放在me.gacl.dao这个包下 -->  
        <javaClientGenerator targetPackage="com.qlm.dao"  
            targetProject="src/main/java" type="XMLMAPPER" >  
            <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
            <property name="enableSubPackages" value="true" />  
        </javaClientGenerator>  
          
        <!-- 配置表信息 -->  
        <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample   
                是否生成 example类   -->    
        <!-- 更改tableName和domainObjectName就可以 -->  
        <table schema="qlm" tableName="tb_qlm_admin"  
            domainObjectName="Admin" enableCountByExample="false"  
            enableDeleteByExample="false" enableSelectByExample="false"  
            enableUpdateByExample="false">             
        </table>  
    </context>  
</generatorConfiguration>  

  

jdbc.properties文件如下

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/qlm?autoReconnect=true&useUnicode=true&characterEncoding=utf-8
username=root
password=root

  

运行-->Run As -->Maven build-->Goals填写mybatis-generator:generate--Run 随后即生成相应代码

猜你喜欢

转载自www.cnblogs.com/Luke-Me/p/8963508.html
今日推荐