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 中的所有查询参数?
基础教程推荐
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01