1. 程式人生 > 程式設計 >IDEA整合MyBatis Generator外掛的使用

IDEA整合MyBatis Generator外掛的使用

1、修改maven的pom檔案

只需要將如下依賴新增到pom.xml檔案中即可。(注意此處是以plugin的方式,放在<plugins></plugins>中間即可)

<plugin>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-maven-plugin</artifactId>
  <version>1.3.2</version>
</plugin>

2、編寫generatorConfig.xml

需要特別注意的是:在IDEA開發環境下,這個檔案需要放置在resources的根目錄下面

檔案內容如下

<?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\.DataGrip2017.3\config\jdbc-drivers\MySQL Connector\J\5.1.45\mysql-connector-java-5.1.45-bin.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://127.0.0.1/mysdql" userId="root" password="root">
    </jdbcConnection>
    <javaTypeResolver>
      <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>
    <!-- 生成模型的包名和位置-->
    <javaModelGenerator targetPackage="com.yingjun.ssm.entity" targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
      <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!-- 生成對映檔案的包名和位置-->
    <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
      <property name="enableSubPackages" value="true"/>
    </sqlMapGenerator>
    <!-- 生成DAO的包名和位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="com.yingjun.ssm.dao" targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>
    <!-- 要生成的表 tableName是資料庫中的表名或檢視名 domainObjectName是實體類名-->
    <table tableName="t_activity" domainObjectName="Activity" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  
  </context>
</generatorConfiguration>

檔案的位置如下

IDEA整合MyBatis Generator外掛的使用

3、建立maven執行項

IDEA整合MyBatis Generator外掛的使用

IDEA整合MyBatis Generator外掛的使用

IDEA整合MyBatis Generator外掛的使用

IDEA整合MyBatis Generator外掛的使用

到此這篇關於IDEA整合MyBatis Generator外掛的使用的文章就介紹到這了,更多相關IDEA整合MyBatis Generator 內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!