Spring MVC,使用post方法,我可以从RequestParam获取请求参数,但是put不会

时间:2017-07-25 02:38:38

标签: spring-mvc put

我是Spring MVC的新手。下面是我的post方法处理程序代码块。

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

我可以从注释RequestParam获取请求参数,即使客户端发送了请求主体中填充了param的请求。为什么呢?

下面是我的put方法处理程序代码块。

@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);
}

当我像帖子一样做同样的事情时,返回一个405“PUT方法”。当我改为使用RequestBody时,它可以工作。为什么呢?

0 个答案:

没有答案