Mybatis Generator 不识别主键

错误场景描述:

在使用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标签。可能是主键没有被识别。

后来在节点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


已发布

分类

来自

标签:

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注