Mybatis Generator 不識別主鍵

錯誤場景描述: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

相關文章
相關標籤/搜索