我是Restful Web服务的新手,并尝试创建Restful Web服务API。 如何将java对象作为参数传递给restful API? 例如,如果我有一个pojo对象'foo',我如何将对象'foo'传递给Restful WS API? 我经历了一些Spring教程,其中@RequestBody用于传递java对象。 还有其他支持类似功能的框架吗?
提前致谢..!
I'm new to Restful web services and trying to create a Restful Web service api. How do I pass a java object as parameter to a restful API? For example, if i have a pojo object 'foo', how can I pass object 'foo' to a Restful WS API? I went through few Spring tutorials in which @RequestBody was used to pass java objects. Is there any other framework supporting similar feature?
Thanks in advance..!
最满意答案
你可以用不同的方式做到这一点。
例如,您可以使用:
Spring MVC + Jackson - 请记住将jackson-databind依赖项添加到项目中 高枕无忧 新泽西我通常会选择Spring MVC,因为我在Spring环境中习惯了它。
Spring MVC示例:
@RequestMapping(value = "/restcall", method = RequestMethod.POST, produces = "application/json") public @ResponseBody Object restCall(@RequestBody(required = true) PojoJSONDescriptor desc) throws IOException { PojoResponseJSONDescriptor res = new PojoResponseJSONDescriptor(); res.setName("Test"); return res; }泽西教程:
泽西教程
You can do it in different ways.
You can, for example, use:
Spring MVC + Jackson - Remember to add jackson-databind dependency to the project RESTEasy JerseyI normally pick Spring MVC, because I'm just used to it in a Spring environment.
Spring MVC Example:
@RequestMapping(value = "/restcall", method = RequestMethod.POST, produces = "application/json") public @ResponseBody Object restCall(@RequestBody(required = true) PojoJSONDescriptor desc) throws IOException { PojoResponseJSONDescriptor res = new PojoResponseJSONDescriptor(); res.setName("Test"); return res; }Jersey tutorial:
Jersey tutorial
更多推荐
发布评论