Spring Data JPA学习三:PagingAndSortingRepository 方法常见错误
1.Sort创建失败
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC,"id"));
Spring boot 2.1版本以上Sort已经不能用new实例化了,可以用以下方式
Sort sort=Sort.by(Sort.Direction.DESC,"id");
源码解析
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