用java实现的通用内存分页函数
来源:互联网 发布:假面骑士腰带淘宝 编辑:程序博客网 时间:2024/06/18 13:01
经常需要用到在内存中进行分页处理,今天写了一个存起来,方便以后直接使用,不用再写了。
public <T> Map<String, Object> getPagingResultMap(List<T> list, Integer currPageNo, Integer pageSize) { Map<String, Object> retMap = new HashMap<>(); if (list.isEmpty()) { retMap.put("result", Collections.emptyList()); retMap.put("pageNo", 0); retMap.put("pageRowNum", 0); retMap.put("totalRowNum", 0); retMap.put("totalPageNum", 0); return retMap; } int totalRowNum = list.size(); int totalPageNum = (totalRowNum - 1) / pageSize + 1; int realPageNo = currPageNo; if (currPageNo > totalPageNum) { realPageNo = totalPageNum; } else if (currPageNo < 1) { realPageNo = 1; } int fromIdx = (realPageNo - 1) * pageSize; int toIdx = totalPageNum * pageSize > totalRowNum ? totalRowNum : realPageNo * pageSize; List<T> result = list.subList(fromIdx, toIdx); retMap.put("result", result); retMap.put("pageNo", realPageNo); retMap.put("pageRowNum", result.size()); retMap.put("totalRowNum", totalRowNum); retMap.put("totalPageNum", totalPageNum); return retMap;}
阅读全文
0 0
- 用java实现的通用内存分页函数
- 一段通用的分页函数
- 通用的分页模型实现.
- JSP实现的Java通用简单分页算法
- 又一种JSP实现的Java通用简单分页算法
- JSP实现的Java通用简单分页算法之三
- Java物理通用分页类实现
- 论坛形式的PHP通用分页函数
- 实现分页的通用存储过程
- 实现分页的通用存储过程
- SQLServer 实现分页的通用存储过程
- 实现的通用分页存储过程
- 实现分页的通用存储过程
- 实现分页的通用存储过程
- /*--实现分页的通用存储过程
- 通用存储过程实现的分页程序
- 通用分页存储过程的实现
- 基于JDBC的通用分页实现
- 关于synchronized的几种用法和相关知识。
- windows命令行方式下打印和设置PATH变量
- SecureRandom实现随机盐salt
- Fragment 生命周期的详情
- ROS -Kinetic<在ubuntu16.04上安装rbx1和arbotix模拟器>
- 用java实现的通用内存分页函数
- SQL事务中锁的用法,与结束进程语句的用法
- JAVA/JS 转码解码(URLEncoder.encode | URLDecoder.decode | encodeURIComponent | decodeURIComponent)
- 【Python学习笔记(三)】:爬虫用到的知识点总结
- 全面解析Java注解
- maven的pom报plugins错误的解决方法.
- Class** 转换成 const Class**的问题
- 无限分类
- 程序员:你为什么要离职?