1.首先给列表分页,假如有5000条数据分批次插入数据库,一批次500个写入
int totalSize = smsSendBatchDetailList.size();
int pageSize = 500;
int totalPage = totalSize / pageSize;
if (totalSize % pageSize != 0) {
totalPage += 1;
if (totalSize < pageSize) {
pageSize = smsSendBatchDetailList.size();
}
}
List<SmsSendBatchDetail> newSmsSendBatchDetailList = new ArrayList<SmsSendBatchDetail>();
for (int pageNum = 1; pageNum < totalPage + 1; pageNum++) {
int starNum = (pageNum - 1) * pageSize;
int endNum = pageNum * pageSize > totalSize ? (totalSize) : pageNum * pageSize;
for (int i = starNum; i < endNum; i++) {
newSmsSendBatchDetailList.add(smsSendBatchDetailList.get(i));
}
smsSendBatchDetailMapper.insertSmsSendBatchDetailList(newSmsSendBatchDetailList);
newSmsSendBatchDetailList.clear();
}