将list转成带分页的参数用map返回给前端
开发过程中 查询的列表不能分页查询 但是前端需要分页的参数 没办法 只能这样搞 把list 转成page参数的数据返回给前端
public class ListPageUtil {
public static <T> Map<String, Object> pageBySubList(List<T> list, int pagesize, int currentPage) {
currentPage = currentPage+1;
int totalcount = list.size();
int pagecount = 0;
List<T> subList;
Map<String, Object> map =new HashMap<String, Object>();
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));
}
}
int pages;
if (list.size()<pagesize) {
pages=1;
}else {
if (subList.size()/pagesize!=0) {
pages=list.size()/pagesize+1;
}else {
pages=list.size()/pagesize;
}
}
map.put("data", subList);
map.put("current", currentPage);
map.put("size", pagesize);
map.put("total", list.size());
map.put("pages", pages);
return map;
}
}
以上是 将list转成带分页的参数用map返回给前端 的全部内容, 来源链接: utcz.com/z/511074.html