spring - How does Spring (Boot) work with Pageable in controllers method argument?
问题描述
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
解决方案
You can look at PageableHandlerMethodArgumentResolver#resolveArgument which calls PageableHandlerMethodArgumentResolverSupport#getPageable
推荐阅读
- java - How do I Implement swap array method in main class?
- eclipse - 如何为非 java 文件启用面包屑导航?
- regex - Advanced Regex Query?
- python - Split spreadsheet into pieces based on the sequences of numbers
- r - 如何使用R在a = c(“a”,“b”)和b = c(“b”,“c”)的两个向量a和b中找到共同元素?
- tkinter - Tkinter 在帧之间传递值
- javascript - 在更改 Javascript 时将表单输入文本格式化为货币
- c++ - Class Functions Object Oriented Program
- api - YouTube 数据 API v3 指标仪表板中的“未指定”凭据是什么?
- mysql - DATAGRIP SQL 编辑器在执行后不会删除语句