2

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

WS/services/patient/1

其中“1”是患者的 ID。所以,在代码中,我这样指定:

@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”),它可以工作......但是,我怎样才能从url中获取id?

4

1 回答 1

8

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

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

于 2012-06-24T22:32:42.513 回答