我知道我可以解决这个问题,但是与将参数拉出参数映射(应根据 javadoc 解码)相比,如果使用带注释的查询参数,行为会有所不同,这似乎很奇怪。这是一个错误,还是只是一个怪癖?
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getAssets(@Context UriInfo info, @QueryParam("q") String searchQuery) {
// The request URI is http://myhost.com/appRoot?q=foo+bar%20baz
// At this point seachQuery="foo bar baz"
// The + has been decoded (along with any % encoded characters)
// Here searchQuery2="foo+bar baz", the '+' has not been decoded
// but the %20 has been
MultivaluedMap<String, String> params = info.getQueryParameters();
String searchQuery2 = params.get("q").get(0);