You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
如果要在 MySQL 中实现批量插入返回自增主键值,只需要在原来代码基础上做如下修改。 <insert id="insertList" useGeneratedKeys="true" keyProperty="id">
和单表一样,增加了useGeneratedKeys和keyProperty两个属性,增加这两个属性后,简单修改测试类,输出 id 值。
//在调用insertList之后
for(SysUser user : userList){
System.out.println(user.getId());
}
执行测试后,可以看到id部分的日志如下。
Error updating database. Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [collection, list]
Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [collection, list]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
……
The text was updated successfully, but these errors were encountered:
org.apache.ibatis.exceptions.PersistenceException:
Error updating database. Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [collection, list]
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: insert into sys_user( user_name, user_password, user_email, user_info, head_img, create_time ) values ( ?, ?, ?, ?, ?, ? ) , ( ?, ?, ?, ?, ?, ? )
Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.binding.BindingException: Parameter 'id' not found. Available parameters are [collection, list]
……
The text was updated successfully, but these errors were encountered: