美文网首页
generatorConfiguration生成文件及配置详解

generatorConfiguration生成文件及配置详解

作者: SimpleLife_9f4a | 来源:发表于2018-07-23 23:05 被阅读0次

数据源为H2数据库,generatorConfiguration_h2.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>
    <!--数据库驱动-->
<!-- h2数据库连接驱动jar包 -->
    <classPathEntry    location="h2-1.4.197.jar"/>
 <!-- 一个数据库一个context --> 
    <context id="DB2Tables"    targetRuntime="MyBatis3">
        <commentGenerator>
<!--suppressDate:**阻止**生成的注释包含时间戳-->
            <property name="suppressDate" value="true"/>
<!--suppressAllComments:**阻止**生成注释-->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接地址账号密码-->
        <jdbcConnection driverClass="org.h2.Driver" connectionURL="jdbc:h2:file:C:/test/h2db" userId="sa" password="">
        </jdbcConnection>
        <javaTypeResolver>
<!--控制是否强制DECIMAL和NUMERIC类型的字段转换为Java类型的java.math.BigDecimal-->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成Model类存放位置-->
        <javaModelGenerator targetPackage="com.test.dao.model" targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--生成Dao类存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.dao.mapper" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--生成对应表及类名-->
<!--enableCountByExample指定是否生成动态查询总条数语句(用于分页的总条数查询);
enableUpdateByExample指定是否生成动态修改语句(只修改对象中不为空的属性);
...-->
        <table tableName="sqlserver_collection" domainObjectName="SQLServerCollectionDo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<!--该元素从将某些属性默认计算的值更改为指定的值。-->
            <columnOverride column="sqlserver_collection_sqlstring" javaType="java.lang.String" jdbcType="VARCHAR" />  
            <columnOverride column="sqlserver_collection_plugin_parm" javaType="java.lang.String" jdbcType="VARCHAR" /> 
        </table>
        <table tableName="wsstomp_collection" domainObjectName="WSStompCollectionDo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
    </context>
</generatorConfiguration>

数据源为mysql数据库,generatorConfiguration_mysql.xml文件,只需要把连接驱动jar包和数据源换掉即可

<?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>
    <!--数据库驱动-->
    <classPathEntry   location="mysql-connector-java-5.1.42.jar"/>
    <context id="DB2Tables"    targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接地址账号密码-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3307/server?useSSL=true" userId="edgeserver" password="123456">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成Model类存放位置-->
        <javaModelGenerator targetPackage="com.test.dao.model" targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="com.test.dao.mapper" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--生成Dao类存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.test.channel.dao" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--生成对应表及类名-->
        <table tableName="sys_widget" domainObjectName="SysWidgetDo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
   
   </context>

</generatorConfiguration>

相关文章

网友评论

      本文标题:generatorConfiguration生成文件及配置详解

      本文链接:https://www.haomeiwen.com/subject/vaggjxtx.html