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 @ 2024-05-14 20:12  zbjice  阅读(179)  评论(0)    收藏  举报