您的位置:首页 > 编程语言 > Java开发

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

2015-03-26 22:58 561 查看
最近的工作中遇到一个问题,在使用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>

可以接收到数据了,另一种方法没测试,不知是否可行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java spring bug
相关文章推荐