1. 程式人生 > >IntelliJ IDEA下MyBatis逆向工程生成工具的使用

IntelliJ IDEA下MyBatis逆向工程生成工具的使用

<?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 >
    <!-- mysql jar 檔案位置 -->
    <classPathEntry location="/Users/fei/Documents/Apache/Maven/localRepository/mysql/mysql-connector-java/5.1.43/mysql-connector-java-5.1.43.jar" />
    <context id="store" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自動生成的註釋 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
            <!-- 是否去除所有自動生成的檔案的時間戳,預設為false -->
             <property name="suppressDate" value="true"/>
        </commentGenerator>
        <!--資料庫連線的資訊:驅動類、連線地址、使用者名稱、密碼 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/SSMBlog"
                        userId="root"
                        password="qwer1234">
        </jdbcConnection>
        <!-- targetPackage:包名稱(自定義)  targetProject:專案路徑(自定義)   -->
        <!--定義model的包名稱-->
        <javaModelGenerator targetPackage="com.ssmblog.entity" targetProject="src/main/java">
            <!-- enableSubPackages:是否讓schema作為包的字尾 -->
            <property name="enableSubPackages" value="false" />
            <!-- 從資料庫返回的值被清理前後的空格  -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <!-- 配置生成相應的實體Mapper.xml,對於Mapper3.X我們需要把type="XMLMAPPER" -->
        <!-- targetPackage:包名稱(自定義)  targetProject:專案路徑(自定義)   -->
        <sqlMapGenerator targetPackage="com.ssmblog.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>

        <!-- 配置生成相應的介面類,對應與Mapper.xml中的一系列CRUD方法SQL語句 -->
        <!-- targetPackage:包名稱(自定義)  targetProject:專案路徑(自定義)   -->
        <javaClientGenerator targetPackage="com.ssmblog.dao" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>

        <!-- 通訊錄人員表 -->
        <table schema="SSMBlog" tableName="contacts" domainObjectName="Contacts"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>

    </context>
</generatorConfiguration>

③如圖,新增一個Run命令,完成之後依次點選Apply和OK;