I have one requirement is to search by pageable and non-pageable,
and in my Java code, I use spring data jpa Pageable class,
Pageable pageable = new
I use this in my code:
public Page retrieveData(@RequestBody CustomParameters query, Pageable pageable, Sort sort) {
if (pageable == null) {
return new PageImpl<>(repository.findAll(query.buildSpecification(), sort));
}
return repository.findAll(query.buildSpecification(), pageable);
}
This has a couple of advantages. If you use this in controllers you can always define a Pageable and a Sort arguments, if the request contains a "page" parameter, a Pageable will be created automatically (if there is a "sort" parameter it will be included in the pageable if it's not null or in the Sort argument if it is).
You can customize the sortResolver and pageableResolver in you configuration and then you have the same behaviour in all your controllers.
This way when you send the request you can specify if you want just a number of records (sendig a "page" parameter, and "size") or if you want them all (not sending those parameters), but you always get the same return structure.