之前用到一个项目 就是将List数据转成PageInfo的分页结构 手写的一个转换格式
应该还有别的解决办法 好像应该可以直接转 后面有时间再研究研究
import com.github.pagehelper.PageInfo;
/**
* @Description: 缓存数据分页 用来替代pagehelp 自动分页方法
* @Param: [page 页码, size 板数, data 缓存数据集合]
**/
public <T>PageInfo<T> getRedisDataPage(Integer page,Integer size,List<T> data){
PageInfo<T> list = new PageInfo<>();
Integer startIndex = (page - 1) * size;
Integer endIndex = Math.min(page * size, data.size());
int total = data.size();
int pages = total%size==0?total/size:(total/size)+1;
data = data.stream()
.skip(startIndex)
.limit(endIndex-startIndex)
.collect(Collectors.toList());
list.setNavigateFirstPage(page>=6?(page-4):1);
list.setNavigateLastPage(total<size?1:list.getNavigateFirstPage()+7);
int pnums[] = null;
int navigateFirstPage = list.getNavigateFirstPage();
if(pages>8){
pnums = new int[8];
for (int i = 0; i < 8; i++) {
pnums[i]=navigateFirstPage;
navigateFirstPage++;
}
}else {
pnums = new int[pages];
for (int i = 0; i < pages; i++) {
pnums[i]=i+1;
}
}
list.setHasNextPage(!(page>=pages));
list.setIsFirstPage(page==1);
list.setIsLastPage(page==pages);
list.setLastPage(list.getNavigateLastPage());
list.setFirstPage(list.getNavigateFirstPage());
list.setList(data);
list.setPageNum(page);
list.setPageSize(size);
list.setPages(pages);
list.setNavigatePages(8);
list.setNextPage(page>=pages?0:page+1);
list.setPrePage(page-1);
list.setHasPreviousPage(!(page==1));
list.setStartRow((page-1)*size+1);
list.setEndRow(total<size?total:page*size);
list.setSize(data.size());
list.setNavigatepageNums(pnums);
list.setTotal(total);
return list;
}
标签:分页,int,List,pages,list,PageInfo,data,page,size From: https://www.cnblogs.com/YinXuanZhiZhi9/p/17704139.html