【问题标题】:The constructor Sort(Sort.Direction, String) is undefined构造函数 Sort(Sort.Direction, String) 未定义
【发布时间】:2020-03-22 10:40:36
【问题描述】:

我想使用带有默认排序方向的 Spring Data JPA 和最新的 spring-boot-starter-parent 2.2.1.RELEASE:

@Override
public Page<ProcessingLogs> findAll(int page, int size) {
    return dao.findAll(PageRequest.of(page,size, new Sort(Sort.Direction.DESC, "createdAt")));
}

但我得到错误:

The constructor Sort(Sort.Direction, String) is undefined

这是最新的代码:https://github.com/spring-projects/spring-data-commons/blob/master/src/main/java/org/springframework/data/domain/Sort.java

你知道我该如何解决这个问题吗?

【问题讨论】:

  • 你链接了源代码,你有没有看一下? Sort.by(Sort.Direction.DESC, "createdAt");.
  • ...我要把new Sort改成Sort.by

标签: java spring spring-boot spring-data-jpa spring-data


【解决方案1】:

像这样使用PageRequest.of(page, size, Sort.by(Sort.Direction.DESC,"createdAt"))

【讨论】:

  • 只是为了扩展。构造函数已被删除,静态 'Sort.by(direction, properties)' 被使用。
猜你喜欢
  • 1970-01-01
  • 2014-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多