0

我在 RestFul webservices Jaxrs2/jersy2 中传递一个员工对象表单客户端

 @GET
    @Path("{empObj}")
    @Produces(MediaType.APPLICATION_XML)
    public Response readPK(@PathParam("empObj")Employee empObj) {
        //do Some Work
        System.out.println(empObj.getName());
        return Response.status(Response.Status.OK).entity(result).build();
    }

如何使用 GET 方法获得这个对象?提前谢谢

4

1 回答 1

1

通过@PathParam在方法参数/类字段上使用,您基本上是在告诉 JAX-RS 运行时将路径段(通常是字符串)注入到您的 (String) 参数中。如果您通过 URI(查询参数、路径参数)直接发送对象(员工)表示,您还应该提供ParamConverterProvider。请注意,这在某些情况下是不可能的,也不是推荐的做法。但是,如果您在消息正文中将对象从客户端发送到服务器,只需删除@PathParamMessageBodyReader将负责将输入流转换为您的类型:

@GET
@Path("{empObj}")
@Produces(MediaType.APPLICATION_XML)
public Response readPK(Employee empObj) {
    //do Some Work
    System.out.println(empObj.getName());
    return Response.status(Response.Status.OK).entity(result).build();
}
于 2013-11-21T14:07:44.420 回答