1.在maven工程中的resource中創建generatorconfig.xml
2.配置generatorconfig.xml
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
|
<?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\xx\.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://xx:3306/xx" userid= "xx" password= "xx" > </jdbcconnection> <javatyperesolver> <property name= "forcebigdecimals" value= "false" /> </javatyperesolver> <!-- 生成模型的包名和位置--> <javamodelgenerator targetpackage= "com.info.statistics.model" targetproject= "src/main/java" > <property name= "enablesubpackages" value= "true" /> <property name= "trimstrings" value= "true" /> </javamodelgenerator> <!-- 生成映射文件的包名和位置--> <sqlmapgenerator targetpackage= "com.info.statistics.mapping" targetproject= "src/main/java" > <property name= "enablesubpackages" value= "true" /> </sqlmapgenerator> <!-- 生成dao的包名和位置--> <javaclientgenerator type= "xmlmapper" targetpackage= "com.info.statistics.dao" targetproject= "src/main/java" > <property name= "enablesubpackages" value= "true" /> </javaclientgenerator> <!-- 要生成的表 tablename是數據庫中的表名或視圖名 domainobjectname是實體類名--> <table tablename= "risk_model_order" domainobjectname= "dsriskmodelorder" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false" ></table> <table tablename= "tel_bill_record" domainobjectname= "dstelbillrecord" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false" ></table> </context> </generatorconfiguration> |
3.配置pom.xml
1
2
3
4
5
6
7
8
9
10
|
<plugin> <groupid>org.mybatis.generator</groupid> <artifactid>mybatis-generator-maven-plugin</artifactid> <version> 1.3 . 2 </version> <configuration> <configurationfile>/src/main/resources/generator/generatorconfig.xml</configurationfile> <overwrite> true </overwrite> <verbose> true </verbose> </configuration> </plugin> |
4.生成對象的兩種方式
方式一:使用idea的maven插件直接快速生成
雙擊mybatis-generator:generate就可生成
方式二:在idea添加一個“run運行”選項,使用maven運行mybatis-generator-maven-plugin插件
mybatis-generator:generate -e 加-e是為了輸出詳細信息
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/fswhq/p/mybatis-generator.html