如何在REST Web服务中PUT多个查询参数

sud*_*udo 4 rest curl web-services jax-rs query-parameters

有谁知道如何在REST Web服务中PUT多个查询参数?我用java编写.我的curl示例是这样的:

curl -X PUT http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read -v
Run Code Online (Sandbox Code Playgroud)

我的计划是:

@PUT
@Path("{user}/{directory:.+}")
public Response doshare(@PathParam("user")String name,
        @PathParam("directory")String dir,
        @QueryParam("name")String sharename,
        @QueryParam("type")String type){
    mongoDAOImpl impl=new mongoDAOImpl();
    Mongo mongo=impl.getConnection("127.0.0.1","27017");
    DB db=impl.getDataBase(mongo,"public");
    DBCollection coll=impl.getColl(db,name);
    DBCollection coll2=impl.getColl(db,"sharedb");
    shareDTO sharedto=new shareDTO();
    String authority=type.toLowerCase();
    if(authority.equals("rd")){
        sharedto.setAuthority("4");
    }else if(authority.equals("rw")){
        sharedto.setAuthority("12");
    }
    sharedto.setTargetuser(sharename);
    sharedto.setRealURI("/home/public/"+name+"/"+dir);
    sharedto.setIdentifier(name);
    sharedto.setParentURI("/home/public/"+sharename);
    boolean bool = false;
    sharefun=new sharefunction();
    if(sharefun.checksubfoldershared(coll, coll2, sharedto)){
        bool=sharefun.sharefiles(coll, coll2, sharedto);
    }else{
        System.out.println("Error");
    }
    // ...
Run Code Online (Sandbox Code Playgroud)

但我只获取名称查询参数.如何获取或如何键入curl命令以获取所有查询参数?

Mik*_*zak 19

你的代码很好 - 问题在于你调用curl的方式.将URL传递给包含"&"的curl时,您必须在URL周围加上引号.否则,shell会将'&'之后的内容解释为单独的命令.

编辑:当我作为评论提交时,我的文字正在被发送.这是你需要做的:

curl -X PUT 'http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read' -v
Run Code Online (Sandbox Code Playgroud)