当前位置:网站首页>对List集合进行分页
对List集合进行分页
2022-04-23 14:00:00 【白云碎里一蓑舟】
list分页工具
/** * 开始分页 * @param list * @param pageNum 页码 * @param pageSize 每页多少条数据 */
public static List startPage(List list, Integer pageNum, Integer pageSize) {
if (list == null) {
return null;
}
if (list.size() == 0) {
return null;
}
Integer count = list.size(); // 记录总数
Integer pageCount = 0; // 页数
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (!pageNum.equals(pageCount)) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
版权声明
本文为[白云碎里一蓑舟]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_49513507/article/details/122043197
边栏推荐
- 编程旅行之函数
- Basic SQL query and learning
- Pytorch 经典卷积神经网络 LeNet
- MySQL [SQL performance analysis + SQL tuning]
- VsCode-Go
- SSM project deployed in Alibaba cloud
- JS brain burning interview question reward
- 初探 Lambda Powertools TypeScript
- Leetcode? The first common node of two linked lists
- Using Jupiter notebook in virtual environment
猜你喜欢
elmo(BiLSTM-CRF+elmo)(Conll-2003 命名实体识别NER)
Express②(路由)
About note 1
Port occupied 1
MySQL [read / write lock + table lock + row lock + mvcc]
Express中间件③(自定义中间件)
SQL learning | complex query
Jenkins construction and use
MySQL index [data structure + index creation principle]
Special test 05 · double integral [Li Yanfang's whole class]
随机推荐
Basic knowledge learning record
解决方案架构师的小锦囊 - 架构图的 5 种类型
Interesting talk about network protocol
商家案例 | 运动健康APP用户促活怎么做?做好这几点足矣
剑南春把文字游戏玩明白了
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
初识go语言
Small case of web login (including verification code login)
Leetcode brush question 𞓜 13 Roman numeral to integer
生产环境——
Scientists say Australian plan to cull up to 10,000 wild horses doesn’t go far enough
1256: bouquet for algenon
Force deduction brush question 101 Symmetric binary tree
Chapter 15 new technologies of software engineering
MySQL 修改主数据库
MySQL [acid + isolation level + redo log + undo log]
Strange bug of cnpm
33 million IOPs, 39 microsecond delay, carbon footprint certification, who is serious?
Express②(路由)
[code analysis (2)] communication efficient learning of deep networks from decentralized data