Pet*_*zov 5 java spring jpa spring-data-jpa spring-boot
我使用以下代码通过JPA和Spring获取数据库行:
return transactionService.findAll(page, size)
public Page<PaymentTransactions> findAll(int page, int size) {
return dao.findAll(PageRequest.of(page,size, new Sort(Sort.Direction.DESC, "createdAt")));
}
Run Code Online (Sandbox Code Playgroud)
我想对该代码实施相同的排序:
return transactionService.getAllBySpecification(specification, pageable)
@Override
public Page<PaymentTransactions> getAllBySpecification(final Specification<PaymentTransactions> specification, final Pageable pageable) {
return dao.findAll(specification, pageable);
}
Run Code Online (Sandbox Code Playgroud)
您知道我如何使用规范实现按列的排序方向。像这样:
return dao.findAll(specification, PageRequest.of(page,size, new Sort(Sort.Direction.DESC, "createdAt")));
Run Code Online (Sandbox Code Playgroud)
附加问题:
我可以设置分页对象的排序方向吗?像这样:
@Override
public Page<PaymentTransactions> getAllBySpecification(final Specification<PaymentTransactions> specification, final Pageable pageable) {
return dao.findAll(specification, PageRequest.of(pageable, new Sort(Sort.Direction.DESC, "createdAt")));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |