mybatis mybatis-generator code automatic generation tool use

1. Download the generator package

Link: https://pan.baidu.com/s/1nmdc0muGoIaid68BffAiKw Password: 555z

 

 

2. Modify the configuration file generator.xml according to your own project

Just modify the six places I marked 1, 2, 3, 4, 5, 6

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 3 <generatorConfiguration>
 4     <!-- 数据库驱动包位置 -->
 5     <classPathEntry location="D:\generator\mysql-connector-java-5.1.34.jar" /> <!-- 1 -->
 6     <context id="DB2Tables" targetRuntime="MyBatis3">
 7         <commentGenerator>
 8             <property name="suppressAllComments" value="true" />
 9         </commentGenerator>
10         <!-- 数据库链接URL、用户名、密码 --><!-- 2-->
11         <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test1?characterEncoding=utf8" userId="root" password="123"> 
12         </jdbcConnection>
13         <javaTypeResolver>
14             <property name="forceBigDecimals" value="false" />
15         </javaTypeResolver>
16         <!-- 生成模型的包名和位置 --> <!-- 3 -->
17         <javaModelGenerator targetPackage="com.mmall.model" targetProject="D:\generator\src">
18             <property name="enableSubPackages" value="true" />
19             <property name="trimStrings" value="true" />
20         </javaModelGenerator > 
21          <!-- Generated map file package name and location -->  <!-- 4 --> 
22          < sqlMapGenerator targetPackage ="com.mmall.mapper" targetProject ="D:\generator\src" > 
23              < property name = "enableSubPackages" value = = "true"  /> 
24          </ sqlMapGenerator > 
25          <!-- The package name and location for generating DAO -->  <!-- 5 --> 
26          < javaClientGenerator type = "XMLMAPPER" targetPackage="com.mmall.dao" targetProject="D:\generator\src">
27             <property name="enableSubPackages" value="true" />
28         </javaClientGenerator>
29         <!-- 要生成那些表(更改tableName和domainObjectName就可以) --><!-- 6 -->
30         <table tableName="sys_user" domainObjectName="SysUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
31         <table tableName="sys_dept" domainObjectName="SysDept" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
32         <table tableName="sys_acl" domainObjectName="SysAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
33         <table tableName="sys_acl_module" domainObjectName="SysAclModule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
34         <table tableName="sys_role" domainObjectName="SysRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
35         <table tableName="sys_role_acl" domainObjectName="SysRoleAcl" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
36         <table tableName="sys_role_user" domainObjectName="SysRoleUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
37         <table tableName="sys_log" domainObjectName="SysLog" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" />
38     </context>
39 </generatorConfiguration>

 

 

 3. Execute the generated statement

Open cmd in the current generator directory, or open cmd and enter the generator directory

  Execute this statement: java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

 

 4. Frequently Asked Questions

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326053163&siteId=291194637