问题
I have a requirement to send dynamic query parameters to REST web service GET method [as shown below].
host:port/app?field1=XXX&value1=VVV&field2=XXX&value2=XXX ....
The consumer can send parameters up to fieldn and valuen. Each field maps to the value.
With this type of requirement, I can't code a finite set of QueryParams on the server side method.
Is there any type of REST library that supports this? I checked RESTEasy and Jersey, and they both don't seem to support this [as far as I checked].
Thanks.
回答1:
Use UriInfo.getQueryParameters(), as following:
@GET
@Path("/foo")
@Produces(MediaType.APPLICATION_JSON)
public Response foo(@Context UriInfo uriInfo) {
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
...
}
It returns a MultivaluedMap. Then just iterate over it.
来源:https://stackoverflow.com/questions/12513307/rest-web-service-dynamic-query-parameters