MySql MyBatis 自动生成主键返回null

<insert id="insert" parameterType="cn.zno.smse.pojo.UserScan" useGeneratedKeys="true" keyProperty="scanId">

无法返回自动生成的ID,

解决:

数据库中设计表,中勾选自动递增。

mysql

    <table tableName="usertest" domainObjectName="Usertest" schema="root" delimitAllColumns="true">
    <generatedKey column="user_id" sqlStatement="MySql" identity="true" />
    <columnRenamingRule searchString="user_id" replaceString="id"/></table>

注: identity 设置为 true 是自增后将 id值放入bean ,设置为false 是先检索 id 值再插入table (oracle 是序列,设置成false,mysql 是自增,设置成true)

原文地址:https://www.cnblogs.com/zno2/p/5016896.html