分页工具类PageUtil
作者:互联网
package com.hst.ces.meetingresource.util;
import java.util.ArrayList;
import java.util.List;
/**
* @author :zy
* @date :Created in 2021/09/08 18:45
* @description:描述
* @version: 1.0
*/
public class PageUtil {
/**
* 开始分页
*
* @param list
* @param pageNum 页码
* @param pageSize 每页多少条数据
* @return
*/
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 != pageCount) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = new ArrayList<>();
try {
pageList = list.subList(fromIndex, toIndex);
} catch (Exception e) {
return pageList;
}
return pageList;
}
}
标签:count,return,分页,pageSize,list,fromIndex,PageUtil,pageNum,工具 来源: https://blog.csdn.net/zouyang920/article/details/122722319