摘要:Java中对集合进行手动分页,并返回 com.github.pagehelper.PageInfo 对象
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| package com.dqv5.util;
import com.github.pagehelper.Page; import com.github.pagehelper.PageInfo;
import java.util.ArrayList; import java.util.List;
public class PageInfoUtil {
public static <T> PageInfo<T> startPage(List<T> list, int pageNum, int pageSize) { int total = list.size(); List<T> subList = list.subList((pageNum - 1) * pageSize, pageNum * pageSize);
Page<T> phPage = new Page<>(); phPage.addAll(subList); phPage.setPageNum(pageNum); phPage.setPageSize(pageSize); phPage.setTotal(total); return new PageInfo<>(phPage); }
public static void main(String[] args) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < 183; i++) { list.add(i + 1); } int pageNum = 2; int pageSize = 10; PageInfo<Integer> pageInfo = startPage(list, pageNum, pageSize); System.out.println(pageInfo); } }
|