开发者

How to get a JSON object and map it into object in spring 3.0 controller using POST method?

开发者 https://www.devze.com 2023-02-04 06:18 出处:网络
I want to add reques开发者_开发技巧t mapping my controller which gets a Json of Array of an object.

I want to add reques开发者_开发技巧t mapping my controller which gets a Json of Array of an object. The JSON will be sent from javascript using post.

Thanks, Kfir


You can do this using Spring's @RequestBody annotation, e.g.

@ResponseBody
public Map<String, Object> handleJsonPost(@RequestBody Map<String, Object> requestJson) {
   ...
   return responseJson;
}

This will also send the return value back as JSON.

You'll also need to include the Jackson library in your application's classpath, and add

<mvc:annotation-driven/> 

to your context (see docs)

0

精彩评论

暂无评论...
验证码 换一张
取 消