I want to add request mapping my controller which gets a Json of Array of an object. The JSON will be sent from javascript using post.
我想添加请求映射我的控制器,它获得一个对象的Json数组。JSON将使用post从javascript发送。
Thanks, Kfir
谢谢,幼狮
1 个解决方案
#1
2
You can do this using Spring's @RequestBody
annotation, e.g.
您可以使用Spring的@RequestBody注释来实现这一点,例如。
@ResponseBody
public Map<String, Object> handleJsonPost(@RequestBody Map<String, Object> requestJson) {
...
return responseJson;
}
This will also send the return value back as JSON.
这也会将返回值发送回JSON。
You'll also need to include the Jackson library in your application's classpath, and add
您还需要在应用程序的类路径中包含Jackson库,并添加。
<mvc:annotation-driven/>
to your context (see docs)
到你的上下文(见文档)
#1
2
You can do this using Spring's @RequestBody
annotation, e.g.
您可以使用Spring的@RequestBody注释来实现这一点,例如。
@ResponseBody
public Map<String, Object> handleJsonPost(@RequestBody Map<String, Object> requestJson) {
...
return responseJson;
}
This will also send the return value back as JSON.
这也会将返回值发送回JSON。
You'll also need to include the Jackson library in your application's classpath, and add
您还需要在应用程序的类路径中包含Jackson库,并添加。
<mvc:annotation-driven/>
to your context (see docs)
到你的上下文(见文档)