其他分享
首页 > 其他分享> > pageUtil

pageUtil

作者:互联网

public class PageUtil {

public static List startPage(List list, Integer pageNum, Integer pageSize) {
if (list == null) {
return null;
}
if (list.size() == 0) {
return new ArrayList();
}
int count = list.size(); // 记录总数
int pageCount = 0; // 页数
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}

//当前页大于总页数
if(pageNum > pageCount)
return new ArrayList();

int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引

if(fromIndex > list.size())
return list;

if (pageNum != pageCount) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
}

标签:pageNum,pageSize,pageCount,list,pageUtil,fromIndex,return
来源: https://www.cnblogs.com/jabez1992/p/16467317.html