List<Long> list = dto.getErrorId();
//每组拆分的数量
int count = 1000;
if (list.size() > count) {
int batch = list.size() / count;
if (list.size() % count != 0) {
//不能被整除就补一次
batch = batch + 1;
}
//循环批量保存每组数据
for (int i = 0; i < batch; i++) {
List<Long> subList;
if (i == batch - 1) {
subList = list.subList(count * i, list.size());
} else {
subList = list.subList(count * i, count * (i + 1));
}
update(po, new QueryWrapper<CfgCheckErrorPO>().eq("check_id", dto.getCheckId()).in("error_id", subList));
}
}
一个集合按一定数量拆分,分批保存
最新推荐文章于 2022-05-18 13:16:48 发布