2016-03-04 108 views
0

我是restful web服务的新手,并尝试创建Restful Web服务api。如何将java对象作为参数传递给restful API?例如,如果我有一个pojo对象'foo',我怎样才能将对象'foo'传递给Restful WS API?我经历了几个Spring教程,其中使用了@RequestBody来传递Java对象。有没有其他框架支持类似的功能?将Java对象传递给restful WS api

在此先感谢..!

回答

0

你可以用不同的方法做到这一点。

可以,例如,使用:

我一般挑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; 
} 

新泽西教程:

Jersey tutorial

+0

谢谢:)我搜索示例程序通过使用球衣Java对象,我没能找到一个清除一个。你能帮我解决一个例子:如何传递一个java对象并在宁静的服务中接收它? – SDJ

+0

我编辑了答案,希望它有帮助。 – sahel

+0

谢谢,这很有帮助。 – SDJ