Spring REST 多个@RequestBody 参数,可能吗? [英] Spring REST multiple @RequestBody parameters, possible?
本文介绍了Spring REST 多个@RequestBody 参数,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经实现了一个 Spring RESTful Web 服务.使用 Jackson JSON 进行对象映射.我有一个接受两个参数的方法.
I've implemented a Spring RESTful web service. Using Jackson JSON for Object Mapping. I have a method that accepts two parameters.
public Person createPerson(
@RequestBody UserContext userContext,
@RequestBody Person person)
客户端如何构造一个请求,其中要在正文中传递多个 JSON 对象?
How would the client construct a request where in multiple JSON objects are to be passed in the body?
这可能吗?
-- 斯里
推荐答案
我很确定那行不通.可能有一种解决方法,但更简单的方法是引入包装对象并更改您的签名:
I'm pretty sure that won't work. There may be a workaround, but the much easier way would be to introduce a wrapper Object and change your signature:
public class PersonContext{
private UserContext userContext;
private Person person;
// getters and setters
}
public Person createPerson(@RequestBody PersonContext personContext)
这篇关于Spring REST 多个@RequestBody 参数,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文