mybatis逆向生成工程

使用maven插件实现

pom文件引入依赖

逆向生成依赖

1
2
3
4
5
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.7</version>
</dependency>

逆向生成maven插件

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.7</version>
<configuration>
<configurationFile>
${basedir}/src/main/resources/generator/generatorConfig.xml
</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>

configurationFile逆向工程配置文件地址,地址可以按照自己的想法写

配置文件

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?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\LongQi-Howard\Downloads\mssql-jdbc-6.4.0.jre8.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库链接URL,用户名、密码 -->
<jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
connectionURL="jdbc:sqlserver://218.28.44.115:8888;database=shiro" userId="sa"
password="longqi.123">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 生成实体类的包名和位置-->
<javaModelGenerator targetPackage="com.howard.shiro.shiro.entity" targetProject="src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false"/>
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成Mapper.xml的包名和位置-->
<sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 生成mapper接口的位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.howard.shiro.shiro.mapper"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<!-- <table tableName="user_info" domainObjectName="UserInfoEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->
<!-- <table tableName="user_role" domainObjectName="UserRoleEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->
<!-- <table tableName="role_operator" domainObjectName="RoleOperatorEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->
<!-- <table tableName="role_menu" domainObjectName="RoleMenuEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->
<!-- <table tableName="role" domainObjectName="RoleEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->
<!-- <table tableName="operator" domainObjectName="OperatorEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->
<!-- <table tableName="menu" domainObjectName="MenuEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->
<!-- <table tableName="dept" domainObjectName="DeptEntity"-->
<!-- enableCountByExample="false" enableUpdateByExample="false"-->
<!-- enableDeleteByExample="false" enableSelectByExample="false"-->
<!-- selectByExampleQueryId="false">-->
<!-- </table>-->

</context>
</generatorConfiguration>

然后运行maven插件下的 mybatis-generator:generator