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

Leon picture Leon · Sep 3, 2012 · Viewed 19.8k times · Source

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 an interceptor?

Thank you very much!

Answer

ashario picture ashario · May 5, 2014

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);