1. 下載mybatis generator插件
下載地址:https://github.com/mybatis/generator/releasesjava
下載完成後,解壓,將features和plugins文件夾的內容複製到eclipse的相應文件夾中,重啓eclipse便可。mysql
2. 使用插件
選中添加generatorConfig文件的項目,右鍵new–>otherjquery
生成的generatorConfig.xml文件配置以下:git
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
<?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="D:\software\eclipse\workspace\UserRegister\WebContent\WEB-INF\lib\mysql-connector-java-5.1.22-bin.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressTypeWarnings" value="true" />
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/test" userId="root" password="root">
</jdbcConnection>
<javaModelGenerator targetPackage="com.demo.domain" targetProject="UserRegister\src">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.demo.mapper" targetProject="UserRegister\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.demo.dao" targetProject="UserRegister\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table schema="general" tableName="T_USERINFO" domainObjectName="User">
<property name="useActualColumnNames" value="false" />
</table>
</context>
</generatorConfiguration>
PS:
targetProject的配置若是寫絕對路徑可能出錯: Project D: does not exist
最好使用絕對路徑。github
3. 生成代碼文件
選中generatorConfig.xml文件,右鍵選擇Generate MyBatis/IBATIS Artifacts便可spring