有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我正在用Jersey开发休息服务。在PUT方法中,我希望使用一个字符串,然后在另一个方法中使用它

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

@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) 个答案

  1. # 1 楼答案

    只需使用字符串参数。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定义为您希望允许客户端能够发送的任何内容类型,或者完全忽略它以接受任何内容类型