Which is equivalent to @Context UriInfo in Spring Rest

I used to work in the Jersey and RESTEasy framework, and now we will use Spring Rest for a new project, I don’t want to pass all the query parameters and matrix parameters as parameters in the method, and usually I will annotate the method with @Context UriInfoand get all the parameters inside my Jersey method or RESTEasy Framework for complex parameters.

I would like to know if there <<20> in Spring REST, which is similar to RESTEasy or Jersey Framework. I would like to get all query parameters or matrix parameters and other parameters, if they are inside the method, instead of passing them as a parameter in the method.

+4
source share
2 answers

I did not find any spring class equivalent to UriInfo. But we can take the same information from the httpservlet request. Suppose the 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

You can set and use these values ​​in a URIinfo object

+1
source

If you use Spring MVC, you can also access it:

@Autowired
ServletContext servletContext;

However, this will give you a more limited set of available methods than the Kaliappan approach.

0
source

Source: https://habr.com/ru/post/1623510/


All Articles