generatorConfiguration配置文件及其详细解读

  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.     <!-- 引入配置文件 -->  
  6.     <properties resource="jdbc.properties"/>  
  7.       
  8.     <!-- 指定数据连接驱动jar地址 -->  
  9.     <classPathEntry location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" />  
  10.       
  11.     <!-- 一个数据库一个context -->  
  12.     <context id="FCRMTables">  
  13.         <!-- 注释 -->  
  14.         <commentGenerator >  
  15.             <property name="suppressAllComments" value="true"/><!-- 是否取消注释 -->  
  16.             <property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳-->  
  17.         </commentGenerator>  
  18.           
  19.         <!-- jdbc连接 -->  
  20.         <jdbcConnection driverClass="${driverClassName}"  
  21.             connectionURL="${url}" userId="${username}"  
  22.             password="${password}" />  
  23.           
  24.         <!-- 类型转换 -->  
  25.         <javaTypeResolver>  
  26.             <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->  
  27.             <property name="forceBigDecimals" value="false"/>  
  28.         </javaTypeResolver>  
  29.           
  30.         <!-- 生成实体类的包名和位置 注意targetProject的值为实体类放在工程中具体位置的相对路径,-->  
  31.         <javaModelGenerator targetPackage="com.qlm.entity"  
  32.             targetProject="src/main/java" >  
  33.             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
  34.             <property name="enableSubPackages" value="true"/>  
  35.             <!-- 是否针对string类型的字段在set的时候进行trim调用 -->  
  36.             <property name="trimStrings" value="true"/>  
  37.         </javaModelGenerator>  
  38.           
  39.         <!-- 生成的SQLMapper映射文件包名和位置 -->  
  40.         <sqlMapGenerator targetPackage="mybatisMapper"  
  41.             targetProject="src/main/resources" >  
  42.             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
  43.             <property name="enableSubPackages" value="true" />  
  44.         </sqlMapGenerator>  
  45.           
  46.         <!-- 生成DAO的包名和位置,这里配置将生成的dao类放在me.gacl.dao这个包下 -->  
  47.         <javaClientGenerator targetPackage="com.qlm.dao"  
  48.             targetProject="src/main/java" type="XMLMAPPER" >  
  49.             <!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->  
  50.             <property name="enableSubPackages" value="true" />  
  51.         </javaClientGenerator>  
  52.           
  53.         <!-- 配置表信息 -->  
  54.         <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample   
  55.                 是否生成 example类   -->    
  56.         <!-- 更改tableName和domainObjectName就可以 -->  
  57.         <table schema="qlm" tableName="tb_qlm_admin"  
  58.             domainObjectName="Admin" enableCountByExample="false"  
  59.             enableDeleteByExample="false" enableSelectByExample="false"  
  60.             enableUpdateByExample="false">             
  61.         </table>  
  62.     </context>  
  63. </generatorConfiguration>  
<?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

 

转载于:https://www.cnblogs.com/jpfss/p/7561669.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis Generator 是一个能够根据数据库表信息自动创建 MyBatis 相应 DAO 和 Mapping 文件的工具,也就是逆向工程。逆向工程需要通过 XML 配置文件来指定数据库连接信息和生成规则。以下是一个简单的 MyBatis Generator 配置文件示例: ```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> <!-- 配置数据库连接信息 --> <context id="DB2Tables" targetRuntime="MyBatis3"> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="123456"> </jdbcConnection> <!-- 配置生成规则 --> <javaModelGenerator targetPackage="com.example.model" targetProject="src/main/java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="com.example.mapper" targetProject="src/main/resources"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.example.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <table tableName="user"></table> </context> </generatorConfiguration> ``` 以上配置文件中: - `<jdbcConnection>` 标签指定了数据库连接信息,包括驱动类、连接地址、用户名和密码。 - `<javaModelGenerator>` 标签用于生成实体类(JavaBean),指定了 JavaBean 生成的包名和存放路径。 - `<sqlMapGenerator>` 标签用于生成 Mapper XML 文件,指定了 Mapper XML 生成的包名和存放路径。 - `<javaClientGenerator>` 标签用于生成 Mapper 接口,指定了 Mapper 接口生成的包名和存放路径。 - `<table>` 标签用于指定要生成的表名。 在使用 MyBatis Generator 生成代码时,只需执行以下命令即可: ```sh java -jar mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml -overwrite ``` 其中 `mybatis-generator-core-1.3.7.jar` 是 MyBatis Generator 工具的 JAR 包,`generatorConfig.xml` 是上述配置文件的路径,`-overwrite` 参数表示覆盖已有文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值