I'm curious to know how does Spring Boot
work with Pageable
in controllers methods? I add a Pageable parameter to my controller method and Spring handle it for me.
There is an example:
@GetMapping("search")
public ResponseEntity<List<ProductDTO>> searchProducts(
@RequestParam(value = "query", required = false, defaultValue = "") String query,
Pageable pageable) {
Specification<Product> spec = Specification.where(null);
if(!StringUtils.isBlank(query)) {
Node rootNode = new RSQLParser().parse(query);
spec = rootNode.accept(new CustomRsqlVisitor<Product>());
}
Page<ProductDTO> page = service.searchProducts(spec, pageable);
// My Additional code....
}
Now let's back to the main question: How does Spring handle Pageable? Then, how can I create the same business for myself to handle Specifications on input methods?
P.S. 1: I used rsql-parser to implement search over my products.
P.S. 2: You can find custom classes that are used to generate Specification under rsql package
Pageable
will be implemented usingLIMIT
andOFFSET
, or a similar approach, depending on the underlying SQL database.