简体   繁体   English

Java Rest Web Service中所有(也是可选的)查询参数的列表

[英]List of all (also optional) query parameters in java rest web service

I want to have all query parameters in a list. 我想在列表中包含所有查询参数。 As well those that were not used in the get method. 以及那些没有在get方法中使用的。 My method: 我的方法:

@GET
@Produces({"text/csv"})
@Path("/somesearch/")
public Response method1(
        @DefaultValue("0") @QueryParam("param1") float param1,
        @DefaultValue("0") @QueryParam("param2") float param2,
        // further optional parameters... not only floats){
    ArrayList<Object> parameters = new ArrayList<Object>();
    parameters.add(param1);
    parameters.add(param2);
    // add further query parameters
    // do something ...
 }

so is there a possibility to obtain all the parameters (even those not set in the GET request) in a list? 所以有可能获得列表中的所有参数(甚至是未在GET请求中设置的参数)吗? I can't use the @context uriInfo with its getQueryParameters() method because it lists the parameters used in the url 我不能将@context uriInfo及其getQueryParameters()方法使用,因为它列出了url中使用的参数

Not sure about the @DefaultValue annotation, but if I had to do it I would have done it something like this.. 不确定@DefaultValue批注,但是如果必须这样做,我会这样做。

 @GET
    @Produces({"text/csv"})
    @Path("/somesearch/")
    public Response method1(@Context UriInfo uriInfo){
        MultivaluedMap<String, String> multiParameters = uriInfo.getQueryParameters();
       // multiParameters contains all the parameters in key-value pairing format
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM