generatorConfiguration生成文件及配置詳解

數據源為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指定是否生成動態(tài)查詢總條數語句(用于分頁的總條數查詢);
enableUpdateByExample指定是否生成動態(tài)修改語句(只修改對象中不為空的屬性);
...-->
        <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>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容