mybatis XML開發 插件一鍵生成配置

mybatis XML開發 插件一鍵生成配置

pom文件:

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.7-SNAPSHOT</version>
        </dependency>

在根目錄建立文件夾conf
裏面新建conf文件

<?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>
    <!-- 中文文檔::::::::::http://mbg.cndocs.ml/index.html  -->
    <!--context 屬性說明
        defaultModelType:指定生成對象的樣式
            1,conditional:類似hierarchical;
            2,flat:所有內容(主鍵,blob)等全部生成在一個對象中;
            3,hierarchical:主鍵生成一個XXKey對象(key class),Blob等單獨生成一個對象,其他簡單屬性在一個對象中(record class)
        targetRuntime:
            1,MyBatis3:默認的值,生成基於MyBatis3.x以上版本的內容,包括XXXBySample;
            2,MyBatis3Simple:類似MyBatis3,只是不生成XXXBySample;
     -->
    <context id="MybatisGenerator" defaultModelType="flat" targetRuntime="MyBatis3">


        <property name="autoDelimitKeywords" value="true"/>
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <!--爲生成的Java模型創建一個toString方法 -->
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>


        <commentGenerator>
            <!-- 是否去除自動生成的註釋,默認 false-->
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://xxxxxx"
                        userId="xxxx"
                        password="xxxxxxx">
        </jdbcConnection>


        <javaTypeResolver>
            <!-- This property is used to specify whether MyBatis Generator should force the use of JSR-310 data types for DATE, TIME,
            and TIMESTAMP fields, rather than using java.util.Date -->
            <property name="useJSR310Types" value="false"/>
        </javaTypeResolver>


        <javaModelGenerator targetPackage="com.kuaishou.is.pm.presentation.domain"
                            targetProject="src/main/java">
            <!-- enableSubPackages:在targetPackage的基礎上,根據數據庫的schema再生成一層package,最終生成的類放在這個package下,默認爲false -->
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources"/>
        <!--specify target package and target project for generated client interfaces and classes-->

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.xxxxx"
                             targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!--<table tableName="pm_team" domainObjectName="Team">-->
        <!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
        <!--</table>-->

<!--        <table tableName="pm_task_type" domainObjectName="NewTaskType">-->
<!--            <generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!--            <columnOverride column="title" jdbcType="VARCHAR" />-->
<!--        </table>-->

        <!--<table tableName="todo_remind_record" domainObjectName="ToDoRemindRecord">-->
            <!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!--        <table tableName="pm_comment" domainObjectName="Comment">-->
        <!--<table tableName="pm_team" domainObjectName="Team">-->
        <!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
        <!--</table>-->

<!--        <table tableName="lab_user_module" domainObjectName="LabUserModule">-->
<!--            <generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
<!--        </table>-->

        <table tableName="task_status_config" domainObjectName="TaskStatusConfig">
            <generatedKey column="id" sqlStatement="MySql" identity="true"/>
        </table>

        <!--<table tableName="目標表名" domainObjectName="dominName">-->
            <!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
        <!--</table>-->
    </context>
</generatorConfiguration>

根據你的表名,想生成的xml 和mapper 放哪,自定義conf

然後
在這裏插入圖片描述
點擊插件一鍵生成代碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章