基于内存分页(三)

一、用流分页

public IPage getPersonDetailPage(PersonDto param) {
    IPage page = new Page<>(param.getPageIndex(), param.getPageSize());
   
    List bookDetailList = this.getPersonDetailList();
   int bookDetailListSize=bookDetailList.size();
    //排序并分页
    bookDetailList = bookDetailListAll.stream().sorted(Comparator.comparing(BookDetail::getBookCode))
                    .skip((param.getPageIndex() - 1) * param.getPageSize()).limit(param.getPageSize()).
                    collect(Collectors.toList());
        page.setRecords(bookDetailList);
        page.setTotal(bookDetailListSize);
        page.setPages(bookDetailListSize % param.getPageSize());
    return page;
}

你可能感兴趣的:(IT,后端)