【发布时间】:2019-07-08 17:28:13
【问题描述】:
我有一个无法转换为 spring findBy... 查询的 JPAQuery。我设法只获得了使用offset 和limit 请求的少量结果。问题是,为了对结果进行实际分页,我需要与使用 spring 存储库方法获得的相同数据(结果总数和 nb 页)。我的代码现在看起来像这样:
public List<Long> findByCountryId(Long countryId, Pageable pageable) {
JPAQuery<Long> query = new JPAQuery<>(this.entityManager);
// innerJoins, where, ...
query
.offset(pageable.getOffset())
.limit(pageable.getPageSize());
return query.fetch();
}
我曾想过自己构建页面,但我想我必须请求整个结果集而不是获取少于 50 行的数据,并且我可以从这个查询中获得数千个结果。
有没有从 JPAQuery 获取页面的干净方法?
【问题讨论】:
标签: java spring-boot jpa pagination spring-data-jpa