Spring mvc 3 : How to get path variable in an interceptor?

后端 未结 3 984
青春惊慌失措
青春惊慌失措 2020-12-29 04:28

In Spring MVC controller, I can get path variable using @PathVariable to get the value of a variable defined in @RequestMapping. How can I get the value of the variable in a

相关标签:
3条回答
  • 2020-12-29 05:11

    Almost 1 year too late, but:

             String[] requestMappingParams = ((HandlerMethod)handler).getMethodAnnotation(RequestMapping.class).params()
    
             for (String value : requestMappingParams) {...
    

    should help

    0 讨论(0)
  • 2020-12-29 05:18

    The thread linked to by Pao worked a treat for me

    In the preHandle() method you can extract the various PathVariables by running the following code

    Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); 
    
    0 讨论(0)
  • 2020-12-29 05:24

    There is a thread in the Spring forums, where someone says, there is no "easy way", so i suppose you would have to parse the URL to get it.

    0 讨论(0)
提交回复
热议问题