java - 方法形参上可以用多个@RequestBody吗,封装不同的对象
天蓬老师
天蓬老师 2017-04-18 10:55:14
0
2
1675

在方法的形参那可以用多个@RequestBody来把json字符串封装成多个对象么?用一个@RequestBody.肯定可以,多个这个注解可以封装多个不同的对象么……

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
迷茫

In fact, there is always one request parameter, because a request only contains one request body. If you understand this, you will understand that Spring MVC does not support multiple @RequestBody.

As for deserializing the content in a request body into several Java instances, it is another problem.
There are three solution directions:

  1. Create a new entity and put your two entities in it. This is the simplest, but not "elegant" enough.

  2. Use Map<String, Object> to accept the request body and deserialize it into each entity yourself.

  3. Similar to method 2, but more generic, implement your own HandlerMethodArgumentResolver. Please refer to: https://sdqali.in/blog/2016/0...

阿神

Let’s list a business scenario

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template