一、useGeneratedKeys
数据库本身具备主键自动增长的功能,才能使用useGeneratedKeys
oracle不支持true
<insert id="insert" useGeneratedKeys="true" keyProperty="idColName">
insert into tableName (colName) values (#{colVal,jdbcType=VARCHAR})
</insert>
(insert and update only) This tells MyBatis to use the JDBC getGeneratedKeys method to retrieve keys generated internally by the database (e.g.auto increment fields in RDBMS like MySQL or SQL Server). Default: false
(仅插入和更新)这告诉MyBatis使用JDBC getGeneratedKeys方法来检索数据库内部生成的密钥(例如,RDBMS中的自动增量字段,例如MySQL或SQL Server)。默认值:false
二、selectKey
当数据库不支持useGeneratedKeys=“true” ,则使用selectKey,例如oracle
<insert id="insert" useGeneratedKeys="true" keyProperty="id