分页
public class LogicPageUtil<T> {/*** 获取指定页码的集合** @param list* @param current 第几页,从 1 开始* @param size 每页大小* @return*/public List<T> getRowsOfPage(List<T> list, int current, int size) {if (CollectionUtils.isEmpty(list)) {return new ArrayList<>();}List<T> rowsOfPage;if (current * size <= list.size()) {rowsOfPage = list.subList((current - 1) * size, current * size);} else {rowsOfPage = list.subList((current - 1) * size, list.size());}return rowsOfPage;}
}
分页2
public class PageUtil {// mysql 分页: select ... limit offset, rowCount/*** 获取偏移量(从 0 开始)** @param pageNum 第几页(从 1 开始)* @param pageSize 每页数据条数* @return*/public static Integer getOffset(Integer pageNum, Integer pageSize) {return (pageNum - 1) * pageSize;}/*** 获取每页数据条数** @param pageSize 每页数据条数* @return*/public static Integer getRowCount(Integer pageSize) {return pageSize;}/*** 获取总共多少页** @param pageSize 每页数据条数* @param totalCount 总数据条数* @return*/public static Integer getTotalPages(Integer pageSize, Integer totalCount) {if (totalCount % pageSize == 0) {return totalCount / pageSize;} else {return totalCount / pageSize + 1;}}
}