对筛选后的list进行分页
作者:互联网
public Result listBkk(TargetSearchSubmit submit) {
// 根据专题id筛选目标
Result targetResult = getTargetBySubjectId(submit, false);
if (targetResult != null) {
return targetResult;
}
// 分页
if (submit.getDoPage().equals(Boolean.TRUE)) {
List<TargetBean> targetBeans = targetMapper.list(submit);
// 专题信息和布控状态
List<TargetBean> result = setSubjectAndbkStatus(targetBeans, true, submit.getBkStatus());
PageInfo<TargetBean> pageInfo = new PageInfo<>(result);
pageInfo.setList(startPage(result, submit.getPageNum(), submit.getPageSize()));
return ResultGenerator.genSuccessResult(pageInfo);
}
// 不分页
List<TargetBean> targetBeans = targetMapper.list(submit);
// 专题信息和布控状态
List<TargetBean> result = setSubjectAndbkStatus(targetBeans, true, submit.getBkStatus());
return ResultGenerator.genSuccessResult(result);
}
/**
* 开始分页
*
* @param list
* @param pageNum 页码
* @param pageSize 每页多少条数据
* @return
*/
public static List startPage(List list, Integer pageNum, Integer pageSize) {
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
}
// 记录总数
Integer count = list.size();
// 页数
Integer pageCount;
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
// 开始索引
int fromIndex;
// 结束索引
int toIndex;
if (!pageNum.equals(pageCount)) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
return list.subList(fromIndex, toIndex);
}
原文链接:https://www.cnblogs.com/loong-hon/p/10863635.html
标签:return,分页,pageSize,List,list,fromIndex,submit,筛选 来源: https://blog.csdn.net/qq_28356887/article/details/120216401