2016-03-04 79 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