最近的工作中遇到一个问题,在使用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的参数是能收到,其他的不行。在网上搜索资料找到解决方法:
有意思的是这个bug在spring的 Resolution是Won't Fix。
我目前的解决方法是在web.xml中加入:
httpPutFormContentFilter
org.springframework.web.filter.HttpPutFormContentFilter
httpPutFormContentFilter
rest
可以接收到数据了,另一种方法没测试,不知是否可行。