错误场景描述:mysql
在使用mybatis-Generator生成xml时,不生成Example,在<table>标签中添加enableCountByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
enableUpdateByExample="false"sql
在生成xml文件时,应该有insert、insertSelective、selectByPrimaryKey、updateByPrimaryKeySelective、updateByPrimaryKey、deleteByPrimaryKey等方法,可是在生成的xml文件中只有insert、insertSelective。后来看xml文件中的resultMap节点里主键id使用的是result标签,而不是id标签。多是主键没有被识别。数据库
后来在节点jdbcConnection里配置useInformationSchema属性,解决了不识别主键问题mybatis
<!--配置数据库--> <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驱动版本。url