一、配置逆向generatoe.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
|
<? 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 > < context id = "DB2Tables" targetRuntime = "MyBatis3" > <!-- 是否生成注释 --> < commentGenerator > < property name = "suppressAllComments" value = "true" /> </ commentGenerator > <!-- 配置数据库连接信息 --> < jdbcConnection driverClass = "com.mysql.jdbc.Driver" connectionURL = "jdbc:mysql://localhost:3306/ssm_crud?serverTimezone=UTC" userId = "root" password = "root" > <!--<property name="useInformationSchema" value="true"/>--> </ jdbcConnection > < javaTypeResolver > < property name = "forceBigDecimals" value = "false" /> </ javaTypeResolver > <!-- 指定javaBean生成的位置 --> < javaModelGenerator targetPackage = "com.atguigu.crud.bean" targetProject = ".\src\main\java" > < property name = "enableSubPackages" value = "true" /> < property name = "trimStrings" value = "true" /> </ javaModelGenerator > <!-- 指定sql映射文件生成的位置 --> < sqlMapGenerator targetPackage = "mapper" targetProject = ".\src\main\resources" > < property name = "enableSubPackages" value = "true" /> </ sqlMapGenerator > <!-- 指定dao接口生成位置,mapper接口 --> < javaClientGenerator type = "XMLMAPPER" targetPackage = "com.atguigu.crud.dao" targetProject = ".\src\main\java" > < property name = "enableSubPackages" value = "true" /> </ javaClientGenerator > <!-- table指定每个表的生成策略 --> < table tableName = "tbl_emp" domainObjectName = "Employee" /> < table tableName = "tbl_dept" domainObjectName = "Department" /> </ context > </ generatorConfiguration > |
二、执行生成代码
1
2
3
4
5
6
7
8
9
10
11
12
|
public class MBGTest { public static void main(String[] args) throws Exception{ List<String> warnings = new ArrayList<String>(); boolean overwrite = true ; File configFile = new File( "mbg.xml" ); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate( null ); } } |
三、结果mapper中未能生成...ByPrimaryKey的方法
四、解决办法
在generatoe.xml的配置数据库连接信息时,添加
<property name="useInformationSchema" value="true"/>
即可解决问题
以上这篇解决myBatis generator逆向生成没有根据主键的select,update和delete问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_38074943/article/details/87531369