stackoverflow :
高赞:
The problem is that when we use application/x-www-form-urlencoded, Spring doesn't understand it as a RequestBody. So, if we want to use this we must remove the @RequestBody annotation.
Then try the following:
```
@RequestMapping(value = "/{email}/authenticate", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = {MediaType.APPLICATION_ATOM_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
public @ResponseBody Representation authenticate(@PathVariable("email") String anEmailAddress, MultiValueMap paramMap) throws Exception {
if(paramMap == null && paramMap.get("password") == null) {
throw new IllegalArgumentException("Password not provided");
}
return null;
}
```
Note that removed the annotation @RequestBody
说的很明白,移除不使用注解即可。MultiValueMap paramMap就可以读取到application/x-www-form-urlencoded 协议里的数据,类的字段和key相对应,即可匹配读取到类的字段上。
补充链接:
Http Post request with content type application/x-www-form-urlencoded not working in Spring