List<ComponentTo> componentList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(componentList)) {
// 数据总数
int totalCount = componentList.size();
// 页大小
int pageSize = 1000;
// 分批上传数据
int lastPageSize = totalCount % pageSize;
// 总页数
int totalPage = lastPageSize > 0 ? totalCount / pageSize + 1 : totalCount / pageSize;
for (int p = 1; p <= totalPage; p++) {
if (lastPageSize == 0) {
componentDao.addAutoList(componentList.subList((p - 1) * pageSize, pageSize * p));
} else {
if (p == totalPage) {
componentDao.addAutoList(componentList.subList((p - 1) * pageSize, totalCount));
} else {
componentDao.addAutoList(componentList.subList((p - 1) * pageSize, pageSize * p));
}
}
TimeUnit.MILLISECONDS.sleep(50);
}
}