Com.mysql.exceptions_踩坑 mybatis-plus Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExceptio...
org.springframework.jdbc.BadSqlGrammarException:###Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExceptin: Table ‘xxx.xxx’ doesn’t exist###The error may exist in com/
org.springframework.jdbc.BadSqlGrammarException:
###Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExceptin: Table ‘xxx.xxx’ doesn’t exist
###The error may exist in com/example/mapper/UserMapper.java (best guess)
###The error may involve defaultParameterMap
###The error occurred while setting parameters
###SQL: SELECT id,name,age,email FROM user
###Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘xxx.xxxr’ doesn’t exist
; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘xxx.xxx’ doesn’t exist
错误原因:原因实体类pojo名字和表名不一致!!mybatis-plus默认规则是实体类和表名以驼峰命名法映射,要求是需要符合这个规则才能执行成功。
由于我使用的是官方的代码生成器,所以有这么一句
strategy.setTablePrefix(pc.getModuleName() + "_");
在输入模块名的时候我输入的是 aaa.bbb.ccc这种格式,刚好和表名对应上,所以这里默认把aaa.bbb去掉了,[email protected],导致找不到表名。
我在代码生成器中加入
/*强制生成TableName,TableId,TableFiled 注解*/
strategy.setEntityTableFieldAnnotationEnable(true);
即可生成TableName,TableId,TableFiled 注解(需要 3.2.1版本以上)。
com.baomidou
mybatis-plus-generator
3.4.0
com.baomidou
mybatis-plus-boot-starter
3.4.0
参考文章:
https://blog.csdn.net/xtho62/article/details/107385514
https://github.com/baomidou/mybatis-plus/issues/1910
https://gitee.com/baomidou/mybatis-plus/issues/IM3XE
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)