Spring MVC - HTTP status code 400 (Bad Request) for missing field which is defined as being not required

后端 未结 2 566
無奈伤痛
無奈伤痛 2020-12-17 22:13

I have Spring MVC application with this controller method.

@RequestMapping(value = \"/add\", method = RequestMethod.POST)
public String addNumber(@RequestPar         


        
相关标签:
2条回答
  • 2020-12-17 22:33

    I came across the same situation, and this happens when your parameter is present in the request with an empty value.

    That is, if your POST body contains "number=" (with empty value), then Spring throws this exception. However, if the parameter is not present at all in the request, it should work without any errors.

    0 讨论(0)
  • 2020-12-17 22:36

    My problem was that some of the headers in a request I was sending with Postman were not present (were unchecked):

    When I checked back the Content-Length header, the request worked fine (200 OK response).

    0 讨论(0)
提交回复
热议问题