我正在使用 Jersey 开发 REST 服务。在 PUT 方法中,我想使用一个 String,然后在另一个方法中使用它。
类似于:我在(测试 REST WEB 服务页面的)“内容”字段中输入一个字符串,然后在注销方法中使用该字符串:
@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 ** 字段中输入什么内容。
谢谢!
最佳答案
只需使用字符串参数。 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
定义为您希望客户端能够发送的任何内容类型,或者完全忽略它以接受任何内容类型。
关于java - 使用通过 PUT 方法发送的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15481324/