Mybatis Generator 不识别主键

解决MyBatis Generator XML生成问题

错误场景描述:

 在使用mybatis-Generator生成xml时,不生成Example,在<table>标签中添加enableCountByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
enableUpdateByExample="false"

在生成xml文件时,应该有insert、insertSelective、selectByPrimaryKey、updateByPrimaryKeySelective、updateByPrimaryKey、deleteByPrimaryKey等方法,但是在生成的xml文件中只有insert、insertSelective。后来看xml文件中的resultMap节点里主键id使用的是result标签,而不是id标签。可能是主键没有被识别。

104946_dE0A_2289161.png

后来在节点jdbcConnection里配置useInformationSchema属性,解决了不识别主键问题

<!--配置数据库-->
<jdbcConnection driverClass="${driver}"
                connectionURL="${url}"
                userId="${username}"
                password="${password}">
    <!--设置可以获取tables remarks信息-->
    <property name="useInformationSchema" value="true"/>
    <!--设置可以获取remarks信息-->
    <property name="remarks" value="true"/>
</jdbcConnection>

还有一种情况是节点jdbcConnection里配置useInformationSchema属性已存在,但是还是只有insert、insertSelective方法,这种情况可能会是mysql驱动版本比较低导致的,可以升级一下mysql驱动版本。

 

 

转载于:https://my.oschina.net/u/2289161/blog/1589630

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值