2012-04-26 20 views
0

在SOAP我使用以下代碼來傳遞參數到一個WebMethod功能參數傳遞雷斯特夫爾web服務

@WebMethod(operationName = "replacinginstrumentname") 
    public String replacinginstrumentname(@WebParam(name = "interface1_name") String interface1_name) 

在哪裏interface1_name爲i傳遞參數。爲此,SOAP有@webparam。

但是我怎樣才能在Restful GET方法中做同樣的事情。 任何幫助將非常感激。

回答

0

有2種方式去:

(1)http://your.service.com/service/interface?interface1_name=YOUR_VALUE

(2)http://your.service.com/service/interface/YOUR_VALUE

那麼你的資源的方法是

的情況下(1 )

@Path("/service") 
public class YourResource{ 

    @GET("/interface") 
    public Response method(@QueryParam(name="interface1_name") String param){ 
     //do the job 
    } 
} 

的情況下(2)

@Path("/service") 
public class YourResource{ 
    @GET("/interface/{iname}") 
    public Response method(@PathParam(name="iname") String param){ 
     //do the job 
    } 
} 
+0

非常感謝您的回覆隊友,因爲我可以從你上面的例子中看到,您在URL中傳遞的價值,不是嗎?但是有可能在函數本身中傳遞參數嗎?以便他的功能可以接受參數並執行操作並返回結果。 – Spaniard89 2012-04-26 14:17:47

+0

任何幫助將非常感激。提前一噸。 – Spaniard89 2012-04-26 14:32:57

+0

不是真的,關於REST的大驚小怪是通過HTTP請求中的所有內容;還有一種將XML數據或JSON數據插入HTTP請求主體的可能性,然後將資源函數作爲參數Java類並將傳入的JSON轉換爲此類的對象。然而,在一個給定的情況下,我認爲這會是矯枉過正。 – 2012-04-26 18:10:14