【问题标题】:RestEasy : GET request with multiple dynamic argumentsRestEasy :使用多个动态参数获取请求
【发布时间】:2016-10-10 09:05:33
【问题描述】:

所需的 URL 应该是这样的:

http://<host>:<port>/path/item?<arguments>

参数键和值应该是多个动态的,所以我不能使用@BeanParam@QueryParam。另外我只能调用这个接口而不执行。

我当前的代码是这样的:

public interface RestService {

    @GET
    @Path("/path/item")
    @Produces(MediaType.APPLICATION_JSON)
    public JsonNode method(@QueryParam("params") String params);
}

我想传递的参数示例:brand=myBrand&price=myPrice

有没有办法做这样的事情?

我的参考资料:

  1. REST Web Service - Dynamic Query Parameters
  2. Passing indefinite Query Parameters with RESTful URL and reading them in RESTEasy

【问题讨论】:

    标签: web-services rest resteasy


    【解决方案1】:

    使用UriInfo.getQueryParameters(),如下:

    @GET
    @Path("/path/item")
    @Produces(MediaType.APPLICATION_JSON)
    public JsonNode method(@Context UriInfo uriInfo) {
        MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); 
        ...
    }
    

    它返回一个MultivaluedMap。然后迭代它。

    【讨论】:

    • 谢谢,但目前我只能使用界面。是否可以传递包含每个参数名称/值的Map?但无论如何,我不再使用这种方法了。好像我不能发送动态参数。
    猜你喜欢
    • 2022-11-14
    • 2012-12-09
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 2020-02-19
    相关资源
    最近更新 更多