使用通过PUT方法发送的字符串

时间:2013-03-18 16:01:50

标签: java rest put

我正在使用Jersey开发REST服务。在PUT方法中,我想使用一个String,然后在另一个方法中使用它。

类似于:我在“内容”字段(TEST REST WEB SERVICES页面)中输入一个字符串,然后我在注销方法中使用该字符串:

@PUT
@Path("logout")
@Produces({"application/json", "text/plain"})
@Consumes(**xxxxx**)
public String logout(**xxxxx**) throws Exception
{
     String reponse = null;
     reponse = new UserManager().logout(**xxxxx**);
     return reponse;
}

所以,我想知道在** xxxxx **字段中放什么。

谢谢!

1 个答案:

答案 0 :(得分:1)

只需使用String参数即可。 JAX-RS运行时将把请求主体编组到其中。

@PUT
@Path("logout")
@Produces({"application/json", "text/plain"})
public String logout(String data) throws Exception {
     String response = null;
     reponse = new UserManager().logout(data);
     return response;
}

您应该将@Consumes定义为您希望客户端能够发送的任何内容类型,或者将其完全保留以接受任何内容类型。

相关问题