Intellij IDEA 14中使用MyBatis generator 自動生成MyBatis程式碼
阿新 • • 發佈:2018-11-07
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
Intellij IDEA 14 作為Java IDE 神器,接觸後發現,非常好用,對它愛不釋手,打算離開eclipse和myeclipse,投入Intellij IDEA的懷抱。
然而在使用的過程中會發現Intellij IDEA也有一些不盡如意的地方,難免會有些不爽:Intellij IDEA 的外掛庫遠不及eclipse的豐富。 mybatis-generator在eclipse中有專門的外掛,而沒有開發出Intellij IDEA能夠使用的外掛。
不過不用灰心,如果你的專案是使用maven組織的,那麼我們可以在Intellij IDEA中使用 mybatis-generator-maven-plugin外掛來完成MyBatis model 和Mapper檔案的自動生成。
STEP 0.在Intellij IDEA建立maven專案(本過程比較簡單,略)
STEP 1. 在maven專案的pom.xml 新增mybatis-generator-maven-plugin 外掛
[html] view plaincopy
- <build>
- <finalName>xxx</finalName>
- <plugins>
- <plugin>
- <groupId
>org.mybatis.generator</groupId>- <artifactId>mybatis-generator-maven-plugin</artifactId>
- <version>1.3.2</version>
- <configuration>
- <verbose>true</verbose>
- <overwrite>true</overwrite>
- </configuration>
- </plugin>
- </plugins>
- </build>
STEP 2. 在maven專案下的src/main/resources 目錄下建立名為 generatorConfig.xml的配置檔案,作為mybatis-generator-maven-plugin 外掛的執行目標,模板如下:
[html] view plain copy
- <?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>
- <!--匯入屬性配置 -->
- <properties resource="generator.properties"></properties>
- <!--指定特定資料庫的jdbc驅動jar包的位置 -->
- <classPathEntry location="${jdbc.driverLocation}"/>
- <context id="default" targetRuntime="MyBatis3">
- <!-- optional,旨在建立class時,對註釋進行控制 -->
- <commentGenerator>
- <property name="suppressDate" value="true" />
- </commentGenerator>
- <!--jdbc的資料庫連線 -->
- <