Ruw*_*han 15 java spring spring-data spring-data-jpa spring-repositories
我希望在单页中获得所有结果,我已尝试过
Pageable p = new PageRequest(1, Integer.MAX_VALUE);
return customerRepository.findAll(p);
Run Code Online (Sandbox Code Playgroud)
以上是行不通的,有没有办法实现这个?似乎无法通过此处询问的自定义查询实现.
Bra*_*zic 30
您的页面请求不正确,因为您在错误的页面上查找结果.它应该是:
new PageRequest(0, Integer.MAX_VALUE);
Run Code Online (Sandbox Code Playgroud)
结果的第一页是0.由于您要返回所有记录,因此它们都在此页面上.
小智 28
更正确的方法是使用Pageable.unpaged()
Pageable wholePage = Pageable.unpaged();
return customerRepository.findAll(wholePage);
Run Code Online (Sandbox Code Playgroud)
如果为Pageable传递null,Spring将忽略它并带来所有数据.
Pageable p = null;
return customerRepository.findAll(p);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19129 次 |
| 最近记录: |