Spring @GetMapping with @RequestParam and @RequestBody fails with HttpMessageNotReadableException

后端 未结 2 1041
醉酒成梦
醉酒成梦 2020-12-11 19:43

Request to the endpoint fails with the following error:

400 Bad request org.springframework.http.converter.HttpMessageNotReadableException: Requir

2条回答
  •  情深已故
    2020-12-11 20:30

    @RequestBody annotation binds the content sent in (POST / PUT) request body with the annotated variable. Since there is no 'body' part in GET request, spring throws HttpMessageNotReadableException to indicate the same.

    As a general rule, you can only use @RequestBody for the requests which can have 'body' content e.g. POST or PUT.

提交回复
热议问题