You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
891 B
Java

package com.jingcheng.template.util;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
public class PageUtils {
public static JSONObject page(List<?> list, Integer pageNum, Integer pageSize){
int page = pageNum;//相当于pageNo
int count = pageSize;//相当于pageSize
int size = list.size();
int pageCount=size/count;
int fromIndex = count * (page - 1);
int toIndex = fromIndex + count;
if (toIndex >= size) {
toIndex = size;
}
if(page>pageCount+1){
fromIndex=0;
toIndex=0;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("list",list.subList(fromIndex, toIndex));
jsonObject.put("total",size);
jsonObject.put("pageNum",pageNum);
jsonObject.put("pageSize",pageSize);
return jsonObject;
}
}