手动分页工具类
手动分页:
/** * Manual paging. * * @param currentPage 当前页数 * @param pageSize 每页条数 * @param list 要执行分页的数组 * @param <T> t * @return pageInfo */ public static <T> PageInfo<T> getPageInfo(int currentPage, int pageSize, List<T> list) { int total = list.size(); if (total > pageSize) { int toIndex = pageSize * currentPage; if (toIndex > total) { toIndex = total; } int totalPage = total % pageSize == 0 ? (total / pageSize) : (total / pageSize) + 1; if (totalPage < currentPage) { list = new ArrayList<>(); } else { list = list.subList(pageSize * (currentPage - 1), toIndex); } } else { list = currentPage == 1 ? list : new ArrayList<>(); } Page<T> page = new Page<>(currentPage, pageSize); page.addAll(list); page.setPages((total + pageSize - 1) / pageSize); page.setTotal(total); return new PageInfo<>(page); }
原文链接:https://blog.csdn.net/lameraaa/article/details/111637528