@Transactional(rollbackFor = Exception.class)
public void insertBatchSomeColumn(List<? extends TStatLogApiContent> apiContents){
if (CollectionUtils.isEmpty(apiContents)) {
throw new IllegalArgumentException("Error: entityList must not be empty");
}
List<TStatLogApiContent> list = (List<TStatLogApiContent>)apiContents;
try (SqlSession batchSqlSession = sqlSessionBatch()) {
int size = list.size();
String sqlStatement = sqlStatement(SqlMethod.INSERT_ONE);
for (int i = 0; i < size; i++) {
batchSqlSession.insert(sqlStatement, list.get(i));
if (i >= 1 && i % 1000 == 0) {
batchSqlSession.flushStatements();
}
}
batchSqlSession.flushStatements();
} catch (Throwable e) {
throw new MybatisPlusException("Error: Cannot execute insertBatch Method. Cause", e);
}
}
MyBatisPlus-sqlSession批量插入
于 2022-10-24 19:09:09 首次发布