Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Spring控制器中接受bot json和常规对象的任何方法_Spring_Spring Mvc_Spring 3 - Fatal编程技术网

在Spring控制器中接受bot json和常规对象的任何方法

在Spring控制器中接受bot json和常规对象的任何方法,spring,spring-mvc,spring-3,Spring,Spring Mvc,Spring 3,这有可能以任何方式实现吗 @RequestMapping(value = "/test", method = RequestMethod.POST) public String test(@RequestBody Person personJson , Person personRegular){ Person person = personJson != null ? personJson : personRegular; } 是的,如果您将Person的json表示作为POST b

这有可能以任何方式实现吗

@RequestMapping(value = "/test", method = RequestMethod.POST)
public String test(@RequestBody Person personJson , Person personRegular){
    Person person = personJson != null ? personJson : personRegular;
}

是的,如果您将
Person
的json表示作为POST body发送,它将绑定到personJson,并且请求参数将绑定到
personRegular
,另一种方法是将
id
作为请求参数发送,通过执行数据库查找并使用
@modeldattribute

注释personRegular,填充
personRegular
模块属性,谢谢。但这不是问题。:)但是,如果我想同时使用这两种方法,那么这个consumes=“application/json”如何?