'Spring boot pagination returning same content
I'm having trouble with spring boot pagination. My pagination settings are:
spring.data.web.pageable.size-parameter=size
spring.data.web.pageable.page-parameter=page
spring.data.web.pageable.default-page-size=10
spring.data.web.pageable.one-indexed-parameters=false
spring.data.web.pageable.max-page-size=20
spring.data.web.pageable.qualifier-delimiter=_
I have an endpoint that holds 2 entities, /blocked-study-groups when I call the endpoint with size=2&page=0 I of course, get both of my entities. The problem comes, when I try to fetch the entities one by one. When I call the endpoint with size=1&page=0 I get this response
{
"content": [
{
"id": "7LRoDdGoKVn",
"name": "a--",
"creator": {
"id": "wLKQgwWQ9Ab",
"nickname": "Giwemik",
"email": "[email protected]",
"avatar": "https://avatars.dicebear.com/api/bottts/a9bf5e6d-b882-412a-a31c-2bae15f90465.svg",
"nameId": "GG7N",
"emailNotifications": false,
"pushNotifications": true
}
}
],
"pageable": {
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 1,
"paged": true,
"unpaged": false
},
"size": 1,
"number": 0,
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"first": true,
"last": false,
"numberOfElements": 1,
"empty": false
}
Which has the same content (not the whole response) as when I call it with size=1&page=1:
{
"content": [
{
"id": "7LRoDdGoKVn",
"name": "a--",
"creator": {
"id": "wLKQgwWQ9Ab",
"nickname": "Giwemik",
"email": "[email protected]",
"avatar": "https://avatars.dicebear.com/api/bottts/a9bf5e6d-b882-412a-a31c-2bae15f90465.svg",
"nameId": "GG7N",
"emailNotifications": false,
"pushNotifications": true
}
}
],
"pageable": {
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"offset": 1,
"pageNumber": 1,
"pageSize": 1,
"paged": true,
"unpaged": false
},
"size": 1,
"number": 1,
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"first": false,
"last": true,
"numberOfElements": 1,
"empty": false
}
I'm not sure if it is needed, but for the record, I also provide controller and service: Controller:
@GetMapping("/{id}/blocked-study-groups")
public Slice<StudyGroupDto> getBlockedStudyGroups(@PathVariable String id, Pageable pageable) {
return studentService.getBlockedStudyGroups(hashidsUtil.decodeId(id), pageable);
}
Service:
public Slice<StudyGroupDto> getBlockedStudyGroups(long id, Pageable pageable) {
Slice<StudyGroup> page = studyGroupRepository.findByBlockedById(id, pageable);
return new SliceImpl<>(dtoMapper.mapStudyGroups(page.getContent()), page.getPageable(), page.hasNext());
}
Why do both pages display the same entity when I have 2 entities in the database?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
