package com.threeclear.mobilelaw.util;
import com.alibaba.fastjson.JSONObject;
import java.util.Collections;
import java.util.List;
public class Utils {
/*
* @Description 多查询手动分页
* @param list
* @param pageNum
* @param pageSize
* @Return com.alibaba.fastjson.JSONObject
* @Author guoxy
* @Date 2021/6/28 15:07
**/
public static JSONObject page(List<?> list, Integer pageNum, Integer pageSize) {
int total = list.size();
int pages = ((Double) Math.ceil(total * 1.0 / pageSize)).intValue();
if (pageNum == 1) {
if (list.size() >= pageSize) {
list = list.subList(0, pageSize);
}
} else {
int offset = (pageNum - 1) * pageSize;
int end = offset + pageSize;
if (list.size() >= end) {
list = list.subList(offset, end);
} else {
if (list.size() > offset) {
list = list.subList(offset, list.size());
} else {
list = Collections.emptyList();
}
}
}
JSONObject jsonObjectResult = new JSONObject();
jsonObjectResult.put("total", total);
jsonObjectResult.put("pageNum", pageNum);
jsonObjectResult.put("pageSize", pageSize);
jsonObjectResult.put("pages", pages);
jsonObjectResult.put("list", list);
return jsonObjectResult;
}
}
多查询手动分页
最新推荐文章于 2022-06-13 08:58:08 发布