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