需求要对集合List<Map<String,Object>>进行一个分页:
/** * 利用subList方法进行分页 * * @param list 分页数据 * @param pagesize 页面大小 * @param currentPage 当前页面(从0开始计算) */ public static List<Map<String,Object>> pageBySubList(List list, int pagesize, int currentPage) { List<Map<String,Object>> subList = new ArrayList<>(); try { int totalcount = list.size(); currentPage = currentPage + 1; int pagecount = 0; 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)); } } } catch (Exception e) { } return subList; }
标签:分页,pagesize,int,list,List,subList,集合,currentPage From: https://www.cnblogs.com/ssbxfsrm/p/16931795.html