38

我想在单页中获得所有结果,我试过了

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

以上不起作用,有什么方法可以实现吗?似乎无法从此处询问的自定义查询中实现。

4

4 回答 4

92

更正确的方法是使用Pageable.unpaged()

Pageable wholePage = Pageable.unpaged();
return customerRepository.findAll(wholePage);
于 2018-12-25T16:37:27.593 回答
47

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

PageRequest.of(0, Integer.MAX_VALUE);

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

于 2017-02-05T15:50:49.307 回答
8

如果您为 Pageable 传递 null,Spring 将忽略它并带来所有数据。

Pageable p = null;
return customerRepository.findAll(p);
于 2018-10-08T11:11:36.897 回答
3

从 spirng-data-commons@2.1.0 开始,正确的语法是PageRequest.of(0, Integer.MAX_VALUE). 你可以看这里

于 2018-12-11T09:51:53.560 回答