错误场景描述:
在使用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驱动版本。
发表回复