繁体   English   中英

Spring Data REST-如何通过JSON忽略字段对实体进行排序?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM