簡體   English   中英

與Jersey REST的PathParam

[英]PathParam with Jersey REST

我正在開發一個REST Web服務,我在URL中使用ID來指定患者,如下所示:

WS/services/patient/1

其中“1”是患者的身份。 所以,在代碼中,我指定如下:

@GET
@Path("{id}")
public void getPatient(@PathParam("id") int cId) {
...
}

我在一個例子中看到了它,但我的失敗了。 我收到這個錯誤:

com.sun.jersey.api.container.ContainerException:方法,public void PresentationLayer.PatientResource.getPatient(int),使用資源的GET注釋,類PresentationLayer.PatientResource,不被識別為使用@HttpMethod注釋的有效Java方法。

我不知道為什么這樣做。 在示例中,我看到它有效。 任何提示?

編輯:如果我不寫@PathParams(“id”),它的工作原理......但是,我怎樣才能從網址獲取id?

com.sun.jersey.api.container.ContainerException:方法, public void PresentationLayer.PatientResource.getPatient(int) ,使用資源的GET注釋,類PresentationLayer.PatientResource,不被識別為使用@HttpMethod注釋的有效Java方法。

您正在嘗試使用不返回響應的方法來服務GET請求(返回類型為void )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM