1.创建DTO对象,构建Specification specification = new Specification(),动态查询方式,构建完动态查询方式之后一般会返回Specification对象
2.构建Pageable对象,这个里面通常用的就是PageRequest.of(page-1,size,Sort.by…)这种分页对象的写法这种都是固定的写法
3.执行findAll的操作,通常来说就将specification,pageable两个对象作为入参,放入findAll()方法里面,返回对象Page 一个分页对象。
public PageImpl(List<T> content, Pageable pageable, long total) {
super(content, pageable);
this.total = pageable.toOptional().filter(it -> !content.isEmpty())//
.filter(it -> it.getOffset() + it.getPageSize() > total)//
.map(it -> it.getOffset() + content.size())//
.orElse(total);
}
getOffset() :
Returns the offset to be taken according to the underlying page and page size.(返回根据基础页面和页面大小获取的偏移量。)
Optional:(该类介绍)