mybatis-plus解决 sqlserver批量插入list报错(转)

原文地址:

mybatis-plus解决 sqlserver批量插入list报错

注:我本地的mybits-plus版本为3.1.0

错误1:

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.

错误2:

未修改代码前,使用默认方法

saveOrUpdateBatch(list)

每次在报错的情况下仅能插入最多1001行数据。

 

跟着杨老师的代码解决问题,由于mybits-plus升级,有个细节需要变更,

InsertBatch 类中

tableInfo.getAllInsertSqlColumn(false)
tableInfo.getAllInsertSqlProperty(false, null)
变更为:
tableInfo.getAllInsertSqlColumnMaybeIf()
tableInfo.getAllInsertSqlPropertyMaybeIf(null)

 

 


上一篇:1、mybatis入门


下一篇:mybaits四-3:获取保存数据的id