前两天写service层的方法中需要对数据库中的数据进行分页查询,本来都是在接口层由前端传过来一个Pageable对象,在接口中对Pageable对象用注解进行定义,所以一时间不知道怎么写,后来得知,其实可以这样写:
可以使用Pageable的实现类AbstractPageRequest的子类PageRequest.of定义
public static PageRequest of(int page, int size, Direction direction, String... properties) {
return of(page, size, Sort.by(direction, properties));
}
例:
int page = 0; int pageSize = 100; PageRequest pageRequest = PageRequest.of(page, pageSize, Sort.Direction.DESC, "id");



