带有Jersey REST的PathParam

Fri*_*n3L 2 java rest jersey

我正在开发一个REST Web服务,我在URL中使用ID来指定患者,如下所示:

WS/services/patient/1

其中"1"是患者的身份.所以,在代码中,我指定如下:

@GET
@Path("{id}")
public void getPatient(@PathParam("id") int cId) {
...
}
Run Code Online (Sandbox Code Playgroud)

我在一个例子中看到了它,但我的失败了.我收到这个错误:

com.sun.jersey.api.container.ContainerException:方法,public void PresentationLayer.PatientResource.getPatient(int),使用资源的GET注释,类PresentationLayer.PatientResource,不被识别为使用@HttpMethod注释的有效Java方法.

我不知道为什么这样做.在示例中,我看到它有效.任何提示?

编辑:如果我不写@PathParams("id"),它的工作原理......但是,我怎样才能从网址获取id?

Gre*_*pff 8

com.sun.jersey.api.container.ContainerException:方法,public void PresentationLayer.PatientResource.getPatient(int),使用资源的GET注释,类PresentationLayer.PatientResource,不被识别为使用@HttpMethod注释的有效Java方法.

您正在尝试GET使用不返回响应的方法(返回类型void)来处理请求.