- 添加依赖
- 添加generatorConfig.xml文件
- 在maven的plugins中运行mybatis-generator插件
- 注意事项:
- (1).generatorConfig.xml文件需要放在resource路径下。
================================================
1、添加依赖
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
|
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version> 3.2 . 8 </version>
</dependency>
</dependencies>
<!-- 控制 Maven 在构建过程中相关配置 -->
<build>
<!-- 构建过程中用到的插件 -->
<plugins>
<!-- 具体插件,逆向工程的操作是以构建过程中插件形式出现的 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version> 1.3 . 0 </version>
<!-- 插件的依赖 -->
<dependencies>
<!-- 逆向工程的核心依赖 -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version> 1.3 . 2 </version>
</dependency>
<!-- 数据库连接池 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version> 0.9 . 2 </version>
</dependency>
<!-- MySQL 驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version> 5.1 . 8 </version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
|
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
39
40
41
42
43
44
|
<?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>
<commentGenerator>
<!-- 关闭自动生成的注释 -->
<property name= "suppressAllComments" value= "true" />
</commentGenerator>
<context id= "DB2Tables" targetRuntime= "MyBatis3" >
<!-- 1 .连接数据库-->
<jdbcConnection
driverClass= "com.mysql.jdbc.Driver"
connectionURL= "jdbc:mysql://localhost:3306/project_crowd"
userId= "root"
password= "root" >
</jdbcConnection>
<javaTypeResolver >
<property name= "forceBigDecimals" value= "false" />
</javaTypeResolver>
<javaModelGenerator targetPackage= "com.it.bean" targetProject= "src/main/java" >
<property name= "enableSubPackages" value= "true" />
<property name= "trimStrings" value= "true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage= "com.it.dao" targetProject= "src/main/java" >
<property name= "enableSubPackages" value= "true" />
</sqlMapGenerator>
<javaClientGenerator type= "XMLMAPPER" targetPackage= "com.it.dao" targetProject= "src/main/java" >
<property name= "enableSubPackages" value= "true" />
</javaClientGenerator>
<table tableName= "t_admin" domainObjectName= "Admin" > </table>
</context>
</generatorConfiguration>
|
3.在maven的plugins中运行mybatis-generator插件
到此这篇关于IDEA中Mybatis的MGB使用逆向工程配置的详细教程的文章就介绍到这了,更多相关idea Mybatis逆向工程内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/repik_3/article/details/108511717