mybatis generator 整合 maven項(xiàng)目 -2018-07-06

1. 在maven<plugins></plugins>中添加如下plugin

      <!-- mybatis generator 插件 -->
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
        <configuration>
        <!--配置generatorConfig.xml所在路徑-->          
        <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
          <verbose>true</verbose>
          <overwrite>true</overwrite>
        </configuration>
      </plugin>

2.在resource中新建generatorConfig.xml 和 generator.properties

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>
    <!--導(dǎo)入屬性配置 -->
    <properties resource="generator/generator.properties"/>

    <!--指定特定數(shù)據(jù)庫的jdbc驅(qū)動jar包的位置 -->
    <classPathEntry location="${jdbc.driverLocation}"/>

    <context id="default" targetRuntime="MyBatis3">


        <!-- optional,旨在創(chuàng)建class時,對注釋進(jìn)行控制 -->
        <commentGenerator>
            <property name="suppressDate" value="true"/>
        </commentGenerator>


        <!--jdbc的數(shù)據(jù)庫連接 -->
        <jdbcConnection driverClass="${jdbc.driverClass}"
                        connectionURL="${jdbc.connectionURL}"
                        userId="${jdbc.userId}"
                        password="${jdbc.password}">
        </jdbcConnection>


        <!-- 非必需,類型處理器,在數(shù)據(jù)庫類型和java類型之間的轉(zhuǎn)換控制-->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- Model模型生成器,用來生成含有主鍵key的類,記錄類 以及查詢Example類
            targetPackage     指定生成的model生成所在的包名
            targetProject     指定在該項(xiàng)目下所在的路徑
        -->
        <javaModelGenerator targetPackage="com.mmall.pojo" targetProject="src/main/java">
            <!-- 是否對model添加 構(gòu)造函數(shù) -->
            <property name="constructorBased" value="true"/>

            <!-- 是否允許子包,即targetPackage.schemaName.tableName -->
            <property name="enableSubPackages" value="false"/>

            <!-- 建立的Model對象是否 不可改變  即生成的Model對象不會有 setter方法,只有構(gòu)造方法 -->
            <property name="immutable" value="false"/>

            <!-- 是否對類CHAR類型的列的數(shù)據(jù)進(jìn)行trim操作 -->
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!--Mapper映射文件生成所在的目錄 為每一個數(shù)據(jù)庫的表生成對應(yīng)的SqlMap文件 -->
        <sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>


        <!-- 客戶端代碼,生成易于使用的針對Model對象和XML配置文件 的代碼
                type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper對象
                type="MIXEDMAPPER",生成基于注解的Java Model 和相應(yīng)的Mapper對象
                type="XMLMAPPER",生成SQLMap XML文件和獨(dú)立的Mapper接口
        -->
        <javaClientGenerator targetPackage="com.mmall.dao" targetProject="src/main/java"
                             type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
            <!--
                    定義Maper.java 源代碼中的ByExample() 方法的可視性,可選的值有:
                    public;
                    private;
                    protected;
                    default
                    注意:如果 targetRuntime="MyBatis3",此參數(shù)被忽略
             -->
            <property name="exampleMethodVisibility" value=""/>
            <!--
                                           方法名計數(shù)器
              Important note: this property is ignored if the target runtime is MyBatis3.
             -->
            <property name="methodNameCalculator" value=""/>

            <!--
                                                為生成的接口添加父接口
             -->
            <property name="rootInterface" value=""/>

        </javaClientGenerator>

        <table tableName="mmall_cart" domainObjectName="Cart"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="mmall_category" domainObjectName="Category"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="mmall_order" domainObjectName="Order"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="mmall_order_item" domainObjectName="OrderItem"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="mmall_pay_info" domainObjectName="PayInfo"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="mmall_product" domainObjectName="Product"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
            <columnOverride column="detail" javaType="String"/>
            <columnOverride column="sub_images" javaType="String"/>
        </table>

        <table tableName="mmall_shipping" domainObjectName="Shipping"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

        <table tableName="mmall_user" domainObjectName="User"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

    </context>
</generatorConfiguration>

generator.properties

jdbc.driverLocation=F:/develop/Maven/repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql://localhost/mmall?useUnicode=true&characterEncoding=utf-8
jdbc.userId=root
jdbc.password=****
01.PNG

雙擊mabatis-generator運(yùn)行

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容