Java批量操作及分页
作者:互联网
一、每次批量插入1000
// 批量操作
if (!CollectionUtils.isEmpty(watchOrderSubBOList)) {
for (WatchOrderSubscribeBO watchOrderSubscribeBO : watchOrderSubBOList) {
list.add(watchOrderSubscribeBO);
if (list.size() == 1000) {
watchOrderSubscribeService.batchInsert(list);
list.clear();
}
}
if (list.size() > 0) {
watchOrderSubscribeService.batchInsert(list);
}
}
二、利用subList分页
// 总记录数
int totalSize = listBO.size();
// 每页N条
int pageSize = page.getPageSize();
// 第几页
int pageNum = page.getStart() + 1;
// 共N页
int totalPage = totalSize % pageSize == 0 ? totalSize / pageSize : (totalSize / pageSize) + 1;
// 起始条数
int startNum = (pageNum - 1) * pageSize > totalSize ? 0 : (pageNum - 1) * pageSize;
// 结束条数
int endNum = pageNum * pageSize > totalSize ? (totalSize) : pageNum * pageSize;
// 后端分页
page.setDatas(listBO.subList(startNum, endNum));
page.setTotalPage(totalPage);
page.setTotal(totalSize);
三、模拟Post请求,访问web
Map<String, String> header = new HashMap<String, String>();
header.put("Content-type", "application/json;charset=utf-8");
header.put("appId", "1000");
LOGGER.info("cmtoken订购鉴OTT权校验请求开始,请求地址={},请求头={},请求参数={}", authenurl, header, reqBody);
String resp = HttpUtils.postUrlStringBody(authenurl, reqBody, header);
标签:Java,分页,pageSize,header,totalSize,批量,list,int,pageNum 来源: https://www.cnblogs.com/nanfengxiangbei/p/16310321.html