Java 分页&;规范使用Spring数据

Java 分页&;规范使用Spring数据,java,pagination,Java,Pagination,我正在尝试将分页添加到我的事务中 下面这个解决方案非常好 List<AccountTransactions> products = accountTransactionRepository.findAll(specification); int skip = (page - 1) * ps; List<AccountTransactionDto> transactionDtos = AccountTransactionMapper.toAccountT

我正在尝试将分页添加到我的事务中

下面这个解决方案非常好

List<AccountTransactions> products = accountTransactionRepository.findAll(specification);

int skip = (page - 1) * ps;

List<AccountTransactionDto> transactionDtos =
        AccountTransactionMapper.toAccountTransactionDtoList(products).stream()
                .skip(skip).limit(ps).collect(Collectors.toList());
List products=accountTransactionRepository.findAll(规范);
int skip=(第1页)*ps;
列出事务DTO=
AccountTransactionMapper.toAccountTransactionDtoList(产品).stream()
.skip(skip).limit(ps).collect(collector.toList());
但我尝试使用spring数据作为第一篇文章中的建议。另一个原因是我认为usign流会导致性能问题

存储库类

@Repository
public interface AccountTransactionRepository extends PagingAndSortingRepository<AccountTransactions, Integer>,
        JpaSpecificationExecutor<AccountTransactions> {
}
@存储库
公共接口AccountTransactionRepository扩展了分页和排序存储库,
JpaSpecificationExecutor{
}
ServiceImpl。阶级

Pageable pageable = PageRequest.of(1, 5);

Page<List<AccountTransactions>> products = accountTransactionRepository.findAll(specification,pageable);
Pageable-Pageable=PageRequest.of(1,5);
页面产品=accountTransactionRepository.findAll(规范,可分页);
但这会返回一个错误

Required type:
List
<AccountTransactions>
Provided:
Page
<AccountTransactions>
所需类型:
列表
提供:
页
我想我需要以返回类型返回页面

当我将其转换为页面时,它会工作,但返回错误的结果


另外,您是否知道从性能角度来看,什么是最好的方法?

findAll
默认情况下返回页面实例。因此,您必须更正以下行:

来自

Page<List<AccountTransactions>> products = accountTransactionRepository.findAll(specification,pageable);
Page products=accountTransactionRepository.findAll(规范,可分页);

Page<AccountTransactions> products = accountTransactionRepository.findAll(pageable);
Page products=accountTransactionRepository.findAll(可分页);

此操作有效,但返回的值错误