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;
        }
  • 相关阅读:
    step_by_step_ABP规约模式
    阅读书单
    关于我
    友情链接
    数据夜话之大数据OLAP数据库概览
    Spark实战
    StormDRPC流程解读
    Curator源码阅读
    Storm使用总结
    JNI相关使用记录
  • 原文地址:https://www.cnblogs.com/yeg0zj/p/15176026.html
Copyright © 2011-2022 走看看