resthub / springmvc-router

Adds route mapping capacity to any "Spring MVC based" webapp. Uses playframework.org Router implementation.
http://resthub.github.com/springmvc-router/
Other
167 stars 63 forks source link

Getting matched router pattern? #59

Closed balatbn closed 10 years ago

balatbn commented 10 years ago

Suppose we have a scenario in which we want to map two(or more) patterns to a single controller method. Is there anyway we can get the matched pattern in the controller method? May be, via a pre-defined attribute from request?

For example, if we have one controller method that can serve both of these requests, is there anyway we can get the pattern "/users{id}" or "/managers/{id}" in the application code?

GET /users/{id} GET /managers/{id}

balatbn commented 10 years ago

We managed to do this by overriding RoutingHandlerMapping and adding following line to getHandlerInternal method

request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, route.path);

Would it be possible to add this to method in next release?

bclozel commented 10 years ago

Hi @balatbn - you're right. This is a URL-based HandlerMapping, so it should make use of this. I'll add this and release it in 1.2.1.

Thanks!

bclozel commented 10 years ago

This fix is available right now in OSS Sonatype repo, for the 1.2.1-SNAPSHOT version.

Note: I've started a new 2.x branch line that relies on Spring 4.