原文地址:
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)