list集合进行分页

/**
     * list集合分页
     *
     * @param list        分页数据
     * @param pagesize    页面大小
     * @param currentPage 当前页面
     */
    @SuppressWarnings("unchecked")
    public static Map<String, Object> pageBySubList(List list,  int currentPage ,int pagesize) {
        Map<String, Object> map = new HashMap<>();
        if (!isEmpty(list)) {
            int totalcount = list.size();
            int pagecount = 0;
            List<String> subList;
            int m = totalcount % pagesize;
            if (m > 0) {
                pagecount = totalcount / pagesize + 1;
            } else {
                pagecount = totalcount / pagesize;
            }
            if (m == 0) {
                subList = list.subList((currentPage - 1) * pagesize, pagesize * (currentPage));
            } else {
                if (currentPage == pagecount) {
                    subList = list.subList((currentPage - 1) * pagesize, totalcount);
                } else {
                    subList = list.subList((currentPage - 1) * pagesize, pagesize * (currentPage));
                }
            }
            map.put("list", subList);
            map.put("pages", pagecount);
            map.put("total", totalcount);
        } else {
            map.put("list", new ArrayList<>());
            map.put("pages", 1);
            map.put("total", 0);
        }
        return map;
    }
原文地址:https://www.cnblogs.com/yeg0zj/p/15176026.html