idea 中增加mybatis 自動生成代碼插件

1、增加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>
    <!-- 數據庫驅動:選擇你的本地硬盤上面的數據庫驅動包-->
    <classPathEntry  location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.45\mysql-connector-java-5.1.45.jar"/>
    <!--<classPathEntry  location="/Users/yb/.m2/repository/mysql/mysql-connector-java/5.1.35/mysql-connector-java-5.1.35.jar"/>-->
    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <!-- 是否去除自動生成的註釋 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--數據庫鏈接URL,用戶名、密碼 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/ty_web" userId="root" password="root">
        </jdbcConnection>
        <!-- 非必需,類型處理器,在數據庫類型和java類型之間的轉換控制-->
        <!-- 默認false,把JDBC DECIMAL 和 NUMERIC 類型解析爲 Integer,爲 true時把JDBC DECIMAL 和
         NUMERIC 類型解析爲java.math.BigDecimal -->
        <javaTypeResolver>
            <!-- 是否使用bigDecimal, false可自動轉化以下類型(Long, Integer, Short, etc.) -->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- 生成實體類地址 -->
        <javaModelGenerator targetPackage="com.laikang.dr.domain" targetProject="src/main/java">
            <!-- 從數據庫返回的值被清理前後的空格 -->
            <property name="trimStrings" value="true"/>
            <!-- enableSubPackages:是否讓schema作爲包的後綴 -->
            <property name="enableSubPackages" value="false"/>
        </javaModelGenerator>

        <!-- 生成mapper xml文件 -->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <!-- enableSubPackages:是否讓schema作爲包的後綴 -->
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!-- 生成mapper xml對應Client-->
        <javaClientGenerator targetPackage="com.laikang.dr.dao" targetProject="src/main/java" type="XMLMAPPER">
            <!-- enableSubPackages:是否讓schema作爲包的後綴 -->
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <!-- 配置表信息 -->
        <!-- schema即爲數據庫名 tableName爲對應的數據庫表 domainObjectName是要生成的實體類 enable*ByExample
            是否生成 example類 -->

        <!--<table schema="dr-center" tableName="im_user_token" domainObjectName="IMUserTokenModel" enableCountByExample="true" enableDeleteByExample="true"-->
        <!--enableSelectByExample="true" enableUpdateByExample="true" mapperName="IMUserTokenDao">-->
        <!--</table>-->
        <!--<table schema="dr-center" tableName="consult" domainObjectName="ConsultModel" enableCountByExample="true" enableDeleteByExample="true"-->
        <!--enableSelectByExample="true" enableUpdateByExample="true" mapperName="ConsultDao">-->
        <!--</table>-->
        <!--<table schema="dr-center" tableName="quick_reply" domainObjectName="QuickReplyModel" enableCountByExample="true" enableDeleteByExample="true"
               enableSelectByExample="true" enableUpdateByExample="true" mapperName="QuickReplyDao">-->

        <table schema="dr-center" tableName="lks_org" domainObjectName="LksOrg" enableCountByExample="true" enableDeleteByExample="true"
               enableSelectByExample="true" enableUpdateByExample="true" mapperName="LksOrgMapper">
        </table>
    </context>
</generatorConfiguration>

2、pom.xml增加插件配製

            <!-- mybatis generator 自動生成代碼插件 -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.6</version>
                <configuration>
                   
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                    <verbose>true</verbose>
                </configuration>
            </plugin>

3、Edit configurations,, 增加maven執行入口

 

 

 

運行一下

在相關的位置查看,發現已經生成了相關文件

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