将Java对象传递给宁静的WS api(Passing Java objects to restful WS api)

编程入门 行业动态 更新时间:2024-10-24 12:27:13
将Java对象传递给宁静的WS api(Passing Java objects to restful WS api)

我是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 Jersey

I 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

更多推荐

本文发布于:2023-08-06 23:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宁静   对象   WS   Java   objects

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!