mybatis-plus解决 sqlserver批量插入list报错
解决版本:3.0.6
原因分析:mybatis-plus默认使用Jdbc3KeyGenerator进行添加,但是sqlserver不支持批量返回id,所以会抛出如下异常
org.apache.ibatis.exceptions.PersistenceException:
### Error flushing statements. Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The statement must be executed before any results can be obtained.
### Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The statement must be executed before any results can be obtained.
决方案: 重写默认saveBatch和saveOrUpdateBatch(缺点是批量添加不能返回id,对于不需要返回id的场景适用)将Jdbc3KeyGenerator替换为NoKeyGenerator
作者:丑男李狗蛋
链接:https://www.jianshu.com/p/49a613811a14
mybatis-plus解决 sqlserver批量插入list报错
https://blog.jeecloud.cn/2020/10/09/20201010065900/