zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    LintCode-Search for a Range
    LintCode-Serialization and Deserialization Of Binary Tree
    LeetCode-Reverse Words in a String
    LeetCode-Reorder List
    LeetCode-Word Break
    LeetCode-Word Ladder
    LeetCode-Valid Palindrome
    cf div2 237 D
    POJ 1759
    cf div2 238 D
  • 原文地址:https://www.cnblogs.com/yeg0zj/p/15176026.html
Copyright © 2011-2022 走看看