public List pageList(List resList, int page, int limit) {
List resultList = null;
if (resList != null && resList.size() != 0) {
if (page != 0 && limit != 0) {
Integer count = resList.size(); // 记录总数
Integer pageCount = 0; // 页数
if (count % limit == 0) {
pageCount = count / limit;
} else {
pageCount = count / limit + 1;
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (page != pageCount) {
fromIndex = (page - 1) * limit;
toIndex = fromIndex + limit;
} else {
fromIndex = (page - 1) * limit;
toIndex = count;
}
resultList = resList.subList(fromIndex, toIndex);
} else {
resultList = resList;
}
}
return resultList;
}
直接在代码里面对list集合进行分页
最新推荐文章于 2023-02-10 11:24:28 发布
本文介绍了如何使用Java实现一个列表分页功能,通过计算总页数和索引范围,确保在给定每页数量限制下返回正确数据片段。核心内容涉及列表操作、分页逻辑及数据筛选技巧。
5042

被折叠的 条评论
为什么被折叠?



