offset 可从0开始
/**
* 利用subList方法进行分页
* @param list 分页数据
* @param limit 页面大小
* @param offset 当前页面
*/
public static List<?> pageBySubList(List<?> list, int limit, int offset) throws Exception{
int totalcount = list.size();
if(totalcount == 0) {
return list;
}else {
int pagecount = 0;
List subList;
int m = totalcount % limit;
pagecount = totalcount / limit;
int lastcout = limit+offset;
if(lastcout<=(totalcount-1)) {
subList = list.subList(offset,lastcout);
}else {
if (m > 0) {
pagecount = totalcount / limit;
subList = list.subList(pagecount*limit,totalcount);
} else {
pagecount = totalcount / limit;
subList = list.subList((pagecount-1)*limit,totalcount);
}
}
return subList;
}
}
标签:分页,pagecount,int,list,subList,totalcount,limit
From: https://www.cnblogs.com/cmdcs/p/17504635.html