我知道这个问题可能会重复,但我尝试了很多但没有成功
我需要在spring boot rest控制器中创建多个RequestParam,如下所示:
@GetMapping("/prd-products/test")
@Timed
public ResponseEntity<List<Test>> getAllTests(@RequestParam (required = false) String search, @RequestParam (required = false) Pageable pageable) {
Page<Test> page = prdProductsService.findAllTest(search, pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/prd-products");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
当我尝试通过 url 调用此服务时:
http://localhost:9116/api/prd-products/test?search=id==1,id==2&pageable=0&size=2
它给了我以下错误
"title": "Bad Request",
"status": 400,
"detail": "Failed to convert value of type 'java.lang.String' to required type 'org.springframework.data.domain.Pageable'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.domain.Pageable': no matching editors or conversion strategy found",
当我尝试发送一个请求参数时,它成功工作。
注意:id==1,id==2是搜索中解析字段的方式