首页 > 编程语言 > 详细

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

时间:2015-03-27 07:42:21      阅读:336      评论:0      收藏:0      [点我收藏+]

最近的工作中遇到一个问题,在使用Spring时,RequestMethod.POST方法能够接收到参数,但RequestMethod.PUT却接收不到传进来的参数,代码大致如下:

@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的参数是能收到,其他的不行。在网上搜索资料找到解决方法:

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

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

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

我目前的解决方法是在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>

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

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

原文:http://my.oschina.net/u/1586157/blog/392470

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!