Jersey Client / JAX-RS and optional (not default) @QueryParam (client side)

前端 未结 2 995
醉梦人生
醉梦人生 2021-02-07 06:47

I have a RESTful API who\'s document says that a certain query parameter is optional, and does not supply a default argument. So, I can either supply the value or not send it i

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 07:37

    You can inject a UriInfo instance (or something else like HttpServletRequest) into your method, and get whatever data you want off of it.

    For example

    @Path("/endpoint")
    @GET
    public Response getEndpoint(@Context UriInfo info, @QueryParam("queryA") String queryA) {
      String queryB = info.getQueryParameters().getFirst("queryB");
      if (null != queryB) {
        // do something with it
      }
      ...
    }
    

提交回复
热议问题