spring boot集成mybatis只剩两个sql 并提示 Cannot obtain primary key information from the database, generated objects may be incomplete

前言

spring boot集成mybatis时只生成两个sql, 搞了一个早上,终于找到原因了

找了很多办法都没有解决, 最后注意到生成sql的时候打印了一句话: 

Cannot obtain primary key information from the database, generated objects may be incomplete

表示生成数据库未完成.

问题描述

在整合mybatis时只是生成了两个insert()函数,并且提示
[WARNING] Cannot obtain primary key information from the database, generated objects may be incomplete

解决方法

在jdbc连接url上加nullCatalogMeansCurrent=true

url=jdbc:mysql://localhost:3306/helloword?useUnicode=true&characterEncoding=utf-8&nullCatalogMeansCurrent=true

亲测已经解决

除此之外, 这一点也要注意

mybatis框架提供了非常好用的逆向工程插件,但是在使用过程中会有很多问题。

我在使用中就遇到了只生成insert和insertSeletive方法,而不生成其他根据primary key查询更新删除的方法。

解决方案:

1.检查数据库中的表是否有主键,如果没有主键是不会生成类似selectByPrimaryKey之类的方法的。

2.检查generatorConfig.xml配置文件中的table标签是否把这些属性设为了false,默认是true,如果设为了false则无法生成。

前两点都是网上很容易找到的,第三点是真正的坑点,希望大家不要被坑了。

3.如果使用的mysql驱动是6.x的,那就无法生成,使用5.x版本的就可以生成。



原文地址:https://www.cnblogs.com/ITPower/p/14406128.html