[英]Spring Data REST - How to sort an entity by JSON ignored field?
我正在使用Spring Data REST,并且在我的项目中有以下实体。
@Data
@Entity
public class Loan{
@Id
@GeneratedValue
private Long id;
@JsonIgnore
private Long createdDate;
private Long amount;
private Long repaymentStartDate;
}
现在,我想按createdDate
对贷款进行排序,该贷款将被自动填充和JSONIgnored来防止更新。 但是,当我调用终结点loans?sort=createdDate
时,我无法按createdDate
loans?sort=createdDate
。
我该如何解决?
这是我的存储库:
public interface LoanRepository extends PagingAndSortingRepository<Loan, Long>{
}
要解决此问题,请尝试将@JsonIgnore
替换为@JsonProperty(access = READ_ONLY)
。 它阻止createdDate
更改,但将其保留在json主体中。
更新
对于Spring Boot 1.5.10+,可以使用@JsonIgnoreProperties("createdDate")
代替@JsonProperty(access = READ_ONLY)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.