如何使用Spring Data Pagination在一页中获得所有结果 [英] How to get all results in one page using Spring Data Pagination

查看:101
本文介绍了如何使用Spring Data Pagination在一页中获得所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过将所有结果都放在一个页面中

I want to get all the results in single page, I've tried with

Pageable p = new PageRequest(1, Integer.MAX_VALUE);
return customerRepository.findAll(p);

以上操作无效,是否有任何方法可以实现?似乎无法通过此处的自定义查询来实现.

Above is not working, is there any methods to achieve this? Seems like it cannot be achieved from custom query as asked here.

推荐答案

您的页面请求不正确,因为您在错误的页面上寻找结果.应该是:

Your page request is incorrect because you are looking for results at the wrong page. It should be:

new PageRequest(0, Integer.MAX_VALUE);

结果的第一页是0.由于您要返回所有记录,因此所有记录都在此页面上.

First page for results is 0. Since you're returning all records, they are all on this page.

这篇关于如何使用Spring Data Pagination在一页中获得所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆