Required request body is missing
来源:6-10 前台商品列表接口开发 part 2
i3kp0d
2021-12-16 01:40:09
问题描述:
当使用Get请求时 如果使用Parm发送请求(如GET: /product/list/search?categoryId=1)就会遇到org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing错误 只能使用Body发送json请求才能被接收 请问如何解决
所有的Get请求都会遇到这样的情况
举例代码
@RestController
@RequestMapping("/product")
public class ProductController {
@Autowired
private ProductService productService;
@GetMapping("/detail/{id}")
public ApiRestResponse<Product> detail(@PathVariable("id") Integer id) {
return ApiRestResponse.success(productService.detail(id));
}
@GetMapping("/list/search")
public ApiRestResponse<PageInfo<Product>> listBySearch(@Valid @RequestBody ProductListSearchReq productListSearchReq) {
return ApiRestResponse.success(productService.listBySearch(productListSearchReq));
}
}1回答
好帮手慕小尤
2021-12-16
同学你好,在此处使用了@RequestBody注解,而该注解主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的),所以请求/list/search需要使用json的方式进行请求。

祝学习愉快!
相似问题