使用排序方向实现Spring Data存储库

时间:2019-04-15 20:10:50

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

我想用private LocalDateTime created_at;的排序方向来实现JPA存储库。我尝试过:

服务

@Override
public Page<PaymentTransactions> findAll(int page, int size) {
    return dao.findAllByCreated_atDesc(PageRequest.of(page, size));
}

存储库

@Repository
public interface PaymentTransactionRepository extends JpaRepository<PaymentTransactions, Integer> {

    Page<PaymentTransactions> findAllByCreated_atDesc(PageRequest of);
}

但是我得到了错误:

 No property created found for type PaymentTransactions!

您知道我如何正确实施此示例吗?

1 个答案:

答案 0 :(得分:0)

您可以这样做:

服务

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