问题描述
我之前在Jersey和RESTEasy框架中工作过,现在我们将Spring Rest用于一个新项目,我不想将所有查询参数和矩阵参数作为方法中的参数传递,通常我会进行注释使用@Context UriInfo
的方法,并且将获取我在Jersey或RESTEasy Framework中的方法中用于复杂参数的所有参数.
I have worked in Jersey and RESTEasy framework earlier and now we will be using Spring Rest for a new project , I don't want to pass all the query params and matrix params as parameters in the method , and usually I would annotate the method with @Context UriInfo
and would get all the parameters inside my method in Jersey or RESTEasy Framework for complex parameters.
我想知道Spring REST中是否有任何@Context UriInfo
,类似于RESTEasy或Jersey框架.我想获取方法内部的所有查询参数或矩阵参数以及其他参数,而不是将它们作为方法中的参数传递.
I would like to know if there is any @Context UriInfo
in Spring REST, which is similar to RESTEasy or Jersey Framework. I would like to get all the query params or matrix params and other params if any inside the method instead of passing them as a parameter in the method.
推荐答案
我没有找到与UriInfo等效的任何Spring类.但是我们可以从httpservlet请求中获取相同的信息.假设网址是http:localhost:8080/services/test?one = 1& two = 2,那么
I did not find any spring class equivalent to UriInfo.But we can take same info from httpservlet request. Suppose, a url is http:localhost:8080/services/test?one=1&two=2, then,
hsr.getServletContext.getContextPath() gives "/services"
hsr.getRequestURI() gives "/services/test"
hsr.getRequestURL() gives complete url "http:localhost:8080/services/test"
hsr.getQueryString() gives "one=1&two=2"
hsr.getServletPath() gives "/test"
hsr.getParameterMap() gives all query strings in a Map as key value pair
您可以在URIinfo对象中设置和使用这些值
You can set and use these values in URIinfo object
这篇关于在Spring Rest中等效于@Context UriInfo的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!