错误代码:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: Too many keys are generated. There are only 1 target objects. You either specified a wrong 'keyProperty' or encountered a driver bug like #1523. at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92) at
问题原因可能是在 mybatis批量插入替换数据的时候 添加了keyColumn=“id” keyProperty=“id” useGeneratedKeys=“true”
replace into table (name, code, create_time, update_time ) values (#{item.name,jdbcType=VARCHAR}, #{item.code,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP})
将 keyColumn=“id” keyProperty=“id” useGeneratedKeys="true"这配置删除即可解决问题。
replace into table (name, code, create_time, update_time ) values (#{item.name,jdbcType=VARCHAR}, #{item.code,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP})



