I'm new with Spring Data and Spring MVC and I don't understand why am I getting empty content:
@RequestMapping(value="/pages", method=RequestMethod.GET)
@ResponseBody
public Page<Client> contactsPages(@RequestParam int page, @RequestParam int size) {
Pageable pageable = new PageRequest(page, size, new Sort("id"));
Page<Client> pageResult = clientRepository.findAll(pageable);
return pageResult;
}
The result of my json when I test the url is:
{"content":[],"last":true,"totalElements":2,"totalPages":1,"size":5,"number":1,"sort":[{"direction":"ASC","property":"id","ignoreCase":false,"nullHandling":"NATIVE","ascending":true}],"first":false,"numberOfElements":0}
And if you have good example making pageable request using Spring Data and Spring MVC and AngularJS; It will be a big help for me.
Ensure that your PageRequest
object is requesting 0
for small sets, not 1
.
The pagination begins from 0
.
This is a common mistake for beginners and is a common redherring when using @Query
in conjunction with Spring pagination. If your @Query
works without pagination and then returns nothing when using it, check the page number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With