llh
2013-02-26 15:06:30
java list通过sublist进行分页
随便给出一个list,最终实现分页,不一定是从数据库里面查的。
代码片段:
/**
* 分页方法
*
* @param list
* 源数据
* @param currentPage
* 当前页
* @param maxNum
* 每页显示几条
* @param pageNum
* 总页数
* @return
*/
public static List getPageList(List list, int currentPage, int maxNum,
int pageNum) {
int fromIndex = 0; // 从哪里开始截取
int toIndex = 0; // 截取几个
if (list == null || list.size() == 0)
return null;
// 当前页小于或等于总页数时执行
if (currentPage <= pageNum && currentPage != 0) {
fromIndex = (currentPage - 1) * maxNum;
if (currentPage == pageNum) {
toIndex = list.size();
} else {
toIndex = currentPage * maxNum;
}
}
return list.subList(fromIndex, toIndex);
}
/**
* 和list之间的转化
*
*/
由AXIN编辑于2014-2-26 15:56:10
猜你喜欢
请下载代码后再发表评论
相关代码
最近下载
最近浏览
微信网友_6802139027345408 LV2
2023年12月31日
lironggang LV38
2023年3月26日
heqian LV17
2023年1月10日
qwdqwdqw LV3
2022年12月2日
tangjj7260 LV18
2021年12月8日
.空运绵熊. LV1
2021年6月5日
Diontll LV3
2020年11月23日
yale1422688399 LV3
2020年11月16日
kerry0304 LV4
2020年5月9日
能不能不存在 LV13
2020年4月30日




