mybatis逆向工程没有生成updateByPrimaryKey问题

转https://blog.csdn.net/weixin_43082657/article/details/108165629

解决思路如下:
1.网上百度后发现说数据表没有主键,检查后没有问题,
2.检查了generatorConfig.xml中table项中的属性

<!--生成全部表tableName设为%-->
<table tableName="task_schedule" domainObjectName="ScheduleJob" enableCountByExample="true" enableUpdateByExample="true"
       enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true" enableUpdateByPrimaryKey="true"
       enableDeleteByPrimaryKey="true" enableInsert="true" enableSelectByPrimaryKey="true">
    <!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>-->
</table>

没有问题!
3.最后发现是jdbc连接器的问题

<jdbcConnection driverClass="${jdbc.driverClass}"
                connectionURL="${jdbc.connectionURL}"
                userId="${jdbc.userId}"
                password="${jdbc.password}">
    <!--解决mysql驱动升级到8.0后不生成指定数据库代码的问题-->
    <property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>

加入这句就可以解决mybatis-generator不识别主键问题了!

<property name="nullCatalogMeansCurrent" value="true" />

4.其它可能

发现运行生成代码的maven插件后,Mapper.java和Mapper.xml中都没有Selective结尾的方法(insertSelective、updateByPrimaryKeySelective)。

后来发现是context标签的targetRuntime属性的原因,将其设置为MyBatis3即可。

posted @   zbjice  阅读(115)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示