第1页上方的java PageRequest返回相同的结果
我有下面的get函数,它应该返回带有可选规范的页面内部的trips
@GetMapping("/trip")
Page<Trip> all(@SearchSpec Specification<Trip> specs,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "1000") int pageSize) {
//return repository.findAll(Specification.where(specs));
return repository.findAll(Specification.where(specs), PageRequest.of(page, pageSize, Sort.by("searchKey").ascending()));
}
现在,当我向我的API发出以下请求时:
http://localhost:8080/trip?page=0&pageSize=2&search=departureAirport:'AMS'
我从API中得到了2条正确的记录(trips)。当我将请求更改为:
http://localhost:8080/trip?page=1&pageSize=2&search=departureAirport:'AMS'
因此,在下一页,我从我的API中获得了下两条记录(trips),这也是正确的,但只要我想转到第2页,API就会返回与第1页相同的记录。因此,第1页上面的每一页都返回相同的记录
我可以增加页面大小,当我这样做时,API会返回更多的记录,但同样,超过1的每一页都会返回相同的记录。因此,只有第0页和第1页上的数据不同
我试图删除规范和排序,但这并没有解决问题
# 1 楼答案
我最终使用了自己的分页算法,因为问题可能与Sqlite有关,我不想更改我的数据库客户端。我在Get请求中使用了以下代码: