【发布时间】:2018-02-18 16:37:24
【问题描述】:
我正在使用 Spring Data REST,我的项目中有以下实体。
@Data
@Entity
public class Loan{
@Id
@GeneratedValue
private Long id;
@JsonIgnore
private Long createdDate;
private Long amount;
private Long repaymentStartDate;
}
现在我想按createdDate 对贷款进行排序,该createdDate 将自动填充并使用JSONIgnored 以防止更新。但是当我调用端点loans?sort=createdDate 时,我无法按createdDate 对贷款进行排序。
我该如何解决这个问题?
这是我的存储库:
public interface LoanRepository extends PagingAndSortingRepository<Loan, Long>{
}
【问题讨论】:
-
restcontroller 长什么样子?请将代码添加到您的问题中。
-
由于我使用的是 Spring Data REST,因此无需编写单独的控制器。当我扩展存储库接口时,Spring 会生成它。
-
当该字段使用“@JsonIgnore”注释时,该字段对用户不可见。所以很明显,不可能按照用户看不到的东西对结果进行排序。
标签: java spring spring-boot spring-data-rest