如何获取Jersey JaxRS中的所有查询参数? [英] How can I grab all query parameters in Jersey JaxRS?

查看:116
本文介绍了如何获取Jersey JaxRS中的所有查询参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个通用的Web服务,需要将所有查询参数都抓取到一个字符串中以便以后解析。我该怎么做?

I am building a generic web service and need to grab all the query parameters into one string for later parsing. How can I do this?

推荐答案

您可以通过 @QueryParam(name)访问单个参数)或通过上下文的所有参数:

You can access a single param via @QueryParam("name") or all of the params via the context:

@POST
public Response postSomething(@QueryParam("name") String name, @Context UriInfo uriInfo, String content) {
     MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); 
     String nameParam = queryParams.getFirst("name");
}

关键是 @Context jax-rs注释,可以用于访问:

The key is the @Context jax-rs annotation, which can be used to access:


UriInfo,Request,HttpHeaders,
SecurityContext,Providers

UriInfo, Request, HttpHeaders, SecurityContext, Providers

这篇关于如何获取Jersey JaxRS中的所有查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆