Spring的RequestMethod.PUT方法接收不到参数

最近的工做中遇到一个问题,在使用Spring时,RequestMethod.POST方法可以接收到参数,但RequestMethod.PUT却接收不到传进来的参数,代码大体以下:java

@Controller
@RequestMapping("/v1")
public class AccountController {
    @RequestMapping(value = "/account/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public Object updateUserInfo(@PathVariable Long id,
                                 @RequestParam(value = "phone", required = false) String phone,
                                 @RequestParam(value = "nickName", required = false) String userName) {
        // do something....
    }
}

id的参数是能收到,其余的不行。在网上搜索资料找到解决方法:web

stackoverflow的原文地址:http://stackoverflow.com/questions/5894270/springmvc-is-not-recognizing-request-body-parameters-if-using-put spring

说是Servlet API的一些问题:https://jira.spring.io/browse/SPR-7414 mvc

有意思的是这个bug在spring的 Resolution是Won't Fix。
app

我目前的解决方法是在web.xml中加入:
测试

<filter>
    <filter-name>httpPutFormContentFilter</filter-name>
    <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>httpPutFormContentFilter</filter-name>
    <servlet-name>rest</servlet-name>
</filter-mapping>

能够接收到数据了,另外一种方法没测试,不知是否可行。ui

相关文章
相关标签/搜索