//list 为全量集合
int batchCount = 1500; //每批插入数目
int batchLastIndex = batchCount;
List<List<ZcAssetsCheckDetail>> shareList = new ArrayList<>();
for (int index = 0; index < list.size(); ) {
if (batchLastIndex >= list.size()) {
batchLastIndex = list.size();
shareList.add(list.subList(index, batchLastIndex));
break;
} else {
shareList.add(list.subList(index, batchLastIndex));
index = batchLastIndex;// 设置下一批下标
batchLastIndex = index + (batchCount - 1);
}
}
if (CollectionUtils.isNotEmpty(shareList)) {
for (List<ZcAssetsCheckDetail> subList : shareList) {
//循环插入数据
zcAssetsCheckDetailDao.insertBatch(subList);
}
}
另附mybatis Oracle批量插入语法
<insert id="insertBatch" parameterType="java.util.List">
insert into tables (col1,col2,col3)
select A.* from
<foreach open="(" close=")" collection="list" item="item" index="index" separator="UNION ALL">
select
#{item.col1} as col1,
#{item.col2} as col2,
#{item.col3} as col3
from dual
</foreach>
A
</insert>