How can I grab all query parameters in Jersey JaxRS?(如何获取 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、请求、HttpHeaders、安全上下文,提供者
UriInfo, Request, HttpHeaders, SecurityContext, Providers
这篇关于如何获取 Jersey JaxRS 中的所有查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取 Jersey JaxRS 中的所有查询参数?
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
