[英]How to make the content type application/x-www-form-urlencoded work with @RequestBody annotation?
When the content type is application/json,@RequestBody can read the request body and deserialized into an Object, but the content type is application/x-www-form-urlencoded, spring-mvc can not support this content type with @RequestBody annotation. 当内容类型为application / json时,@ RequestBody可以读取请求体并反序列化为Object,但内容类型为application / x-www-form-urlencoded,spring-mvc不能使用@RequestBody注释支持此内容类型。
In my project, I encountered this problem, I want to support both of them at the same time, but I don't want to lose the convenience of @RequestBody. 在我的项目中,我遇到了这个问题,我想同时支持它们,但我不想失去@RequestBody的便利。
Is there another way to support these two content type and like @RequestBody can auto deserialized request body into an Object? 有没有其他方法来支持这两种内容类型,像@RequestBody可以自动反序列化请求体到一个对象?
@RequestMapping(value = "/test")
public String test(@RequestBody User user) {
return user.toString();
}
Is there another way to support these two content type and like @RequestBody can auto deserialized request body into an Object? 有没有其他方法来支持这两种内容类型,像@RequestBody可以自动反序列化请求体到一个对象?
Negative. 负。
What you can do is use FormHttpMessageConverter to deserialize into a MultiValueMap<String, String>
. 你可以做的是使用FormHttpMessageConverter反序列化为MultiValueMap<String, String>
。 You can then write an transformer to take that and create a User
object. 然后,您可以编写一个转换器来获取它并创建一个User
对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.