0

I am a newbie in Spring MVC. Below is my post method handler code block.

@RequestMapping(value = "/fruit", method = RequestMethod.POST, produces = {"application/json"})
public void newFruitVideo(
        @RequestParam String catalog
) {
    String result = "";
    JSONObject catalogJson = JSONObject.parseObject(catalog);
}

I can get the request param from annotation RequestParam even though the client send the request with param filled in request body. Why?

Below is my put method handler code block.

@RequestMapping(value = "/fruit/{id}", method = RequestMethod.PUT, produces = {"application/json"})
public void editFruitVideo(
        @PathVariable Long id,
        @RequestParam String catalog
) {
    String result = "";
    JSONObject catalogJson = JSONObject.parseObject(catalog);
}

When I do the same thing like the post, a 405 "PUT method is not supported" is returned. When I change to use RequestBody, it works. Why?

  • What is your first request look like. With `POST` & `PUT`, you will get `RequestBody`. – Rana_S Jul 25 '17 at 03:28
  • Possible duplicate of [Can Spring MVC have request parameters for an HTTP PUT method, or must I use post? Which should I use to be RESTful?](https://stackoverflow.com/questions/8250439/can-spring-mvc-have-request-parameters-for-an-http-put-method-or-must-i-use-pos) – Guillaume F. Jul 25 '17 at 03:40

0 Answers0