springboot2.2.1(含)以上的版本Sort已经不能再实例化了,构造方法已经是私有的了!
private Sort(Sort.Direction direction, List<String> properties) {
if (properties != null && !properties.isEmpty()) {
this.orders = (List)properties.stream().map((it) -> {
return new Sort.Order(direction, it);
}).collect(Collectors.toList());
} else {
throw new IllegalArgumentException("You have to provide at least one property to sort by!");
}
}
我们可以改用Sort.by获得Sort对象
例子:
Sort sort = new Sort(Direction.DESC, "id");
Pageable pageable = PageRequest.of(page, size,sort);
改成
Pageable pageable = PageRequest.of(page, size,Sort.by(Direction.DESC, "id"));
Sort.by()可以一个或多个字段排序