使用myBatisPlus之后要重写saveBatch,因为sqlServer在批量插入的时候官方驱动只返回1个id.
重写saveBatch的相关资料:https://www.jianshu.com/p/49a613811a14
重写后上传批量插入报错,错误如下。
定位后的错误位置如下:
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveBatch(Collection<T> entityList, int batchSize) {
int i = 0;
String sqlStatement = SqlHelper.table(currentModelClass()).getSqlStatement(NoahSqlMethod.INSERT_BATCH.getMethod());
try (SqlSession batchSqlSession = sqlSessionBatch()) {
for (T anEntityList : entityList) {
batchSqlSession.insert(sqlStatement, anEntityList);
if (i >= 1 && i % batchSize == 0) {
batchSqlSession.flushStatements();
}
i++;
}
batchSqlSession.flushStatements();
}
return true;
}
确定过自己的mapper文件已经被打包进入target中。
希望厉害的大佬帮忙看一下。
---------------------------------------------------------
在insert中我的stateMent是com.yms.dao.master.BomRelPnDao.insertBatch,但是我的dao层没有。我的dao层的确不需要。
我感觉应该是托管给数据库的。