1. pom.xml下添加dependency
1
2
3
4
5
|
<dependency> <groupid>org.mybatis.generator</groupid> <artifactid>mybatis-generator-core</artifactid> <version> 1.3 . 2 </version> </dependency> |
2. pom.xml下plugins插入plugin
1
2
3
4
5
6
7
8
9
10
11
12
|
<plugin> <groupid>org.mybatis.generator</groupid> <artifactid>mybatis-generator-maven-plugin</artifactid> <version> 1.3 . 2 </version> <goals> <glal>generator</glal> </goals> <configuration> <verbose> true </verbose> <overwrite> true </overwrite> </configuration> </plugin> |
3. src/main/resource下创建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
39
40
41
42
43
|
<?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:\repositorygit\mybatisgenerator1.3.5\mysql-connector-java-5.1.36.jar" /> <context id= "mysqltables" targetruntime= "mybatis3" > <!-- 生成的‘实体类'将 implements serializable --> <plugin type= "org.mybatis.generator.plugins.serializableplugin" ></plugin> <!-- 是否生成注释--> <commentgenerator> <property name= "suppressallcomments" value= "true" /> <property name= "suppressdate" value= "true" /> </commentgenerator> <jdbcconnection driverclass= "com.mysql.jdbc.driver" connectionurl= "jdbc:mysql://127.0.0.1:3306/test" userid= "root" password= "mysql" /> <!--指定生成的类型为java类型,避免数据库中number等类型字段 --> <javatyperesolver> <property name= "forcebigdecimals" value= "false" /> </javatyperesolver> <!--自动生成的实体的存放包路径 --> <javamodelgenerator targetpackage= "com.example.dao.mybatis.entity" targetproject= "src/main/java" > <property name= "enablesubpackages" value= "true" /> <property name= "trimstrings" value= "true" /> </javamodelgenerator> <!--自动生成的*mapper.xml文件存放路径 --> <sqlmapgenerator targetpackage= "com.example.dao.mybatis.sqlmap" targetproject= "src/main/java" > <property name= "enablesubpackages" value= "true" /> </sqlmapgenerator> <!--自动生成的*mapper.java存放路径 --> <javaclientgenerator type= "xmlmapper" targetpackage= "com.example.dao.mybatis.mapper" targetproject= "src/main/java" > <property name= "enablesubpackages" value= "true" /> </javaclientgenerator> <table tablename= "user" domainobjectname= "user" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false" > <generatedkey column= "id" sqlstatement= "select last_insert_id()" identity= "false" /> </table> </context> </generatorconfiguration> |
4. 执行mybatis-generator:generate运行生成实体类、mapper和xml映射文件
总结
以上所述是小编给大家介绍的maven下 mybatis-generator使用,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
原文链接:https://www.cnblogs.com/liudj/p/9566291.html