Java SpringDataREST-如何按JSON忽略字段对实体排序?

Java SpringDataREST-如何按JSON忽略字段对实体排序?,java,spring,spring-boot,spring-data-rest,Java,Spring,Spring Boot,Spring Data Rest,我正在使用SpringDataREST,我的项目中有以下实体 @Data @Entity public class Loan{ @Id @GeneratedValue private Long id; @JsonIgnore private Long createdDate; private Long amount; private Long repaymentStartDate; } 现在,我想按照createdDate对贷款

我正在使用SpringDataREST,我的项目中有以下实体

@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
对贷款进行排序

我该如何解决这个问题

这是我的存储库:

public interface LoanRepository extends PagingAndSortingRepository<Loan, Long>{

}
public interface LoanRepository扩展了分页和排序存储库{
}

若要解决此问题,请尝试将
@JsonIgnore
替换为
@JsonProperty(access=READ\u)
。它防止
createdDate
更改,但仍保留在json正文中

已更新


对于Spring Boot 1.5.10+而不是
@JsonProperty(access=READ_ONLY)
您可以在实体顶部使用
@JsonIgnoreProperties(“createdDate”)

restcontroller的外观如何?请为您的问题添加代码。因为我使用的是Spring Data REST,所以不需要编写单独的控制器。当我扩展存储库接口时,Spring将生成它。当该字段用“@JsonIgnore”注释时,该字段对用户不可见。因此,很明显,不可能按用户看不到的内容对结果进行排序。