如何获取 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过
@QueryParam("name")
访问单个参数,也可以通过上下文访问所有参数:关键是
@Context
jax-rs注释,可用于访问:You can access a single param via
@QueryParam("name")
or all of the params via the context:The key is the
@Context
jax-rs annotation, which can be used to access:请求 URI 的未解析查询部分可以从
UriInfo
对象中获取:The unparsed query part of the request URI can be obtained from the
UriInfo
object:在已接受的答案中添加更多内容。还可以通过以下方式获取所有查询参数,而无需向方法添加额外的参数,这在维护 swagger 文档时可能很有用。
参考
Adding a bit more to the accepted answer. It is also possible to get all the query parameters in the following way without adding an additional parameter to the method which maybe useful when maintaining swagger documentation.
ref