我想在单页中获得所有结果,我试过了
Pageable p = new PageRequest(1, Integer.MAX_VALUE);
return customerRepository.findAll(p);
以上不起作用,有什么方法可以实现吗?似乎无法从此处询问的自定义查询中实现。
我想在单页中获得所有结果,我试过了
Pageable p = new PageRequest(1, Integer.MAX_VALUE);
return customerRepository.findAll(p);
以上不起作用,有什么方法可以实现吗?似乎无法从此处询问的自定义查询中实现。
更正确的方法是使用Pageable.unpaged()
Pageable wholePage = Pageable.unpaged();
return customerRepository.findAll(wholePage);
您的页面请求不正确,因为您在错误的页面上查找结果。它应该是:
PageRequest.of(0, Integer.MAX_VALUE);
结果的第一页是 0。由于您要返回所有记录,因此它们都在此页面上。
如果您为 Pageable 传递 null,Spring 将忽略它并带来所有数据。
Pageable p = null;
return customerRepository.findAll(p);
从 spirng-data-commons@2.1.0 开始,正确的语法是PageRequest.of(0, Integer.MAX_VALUE)
. 你可以看这里