resthub / springmvc-router

Adds route mapping capacity to any "Spring MVC based" webapp. Uses playframework.org Router implementation.

Home Page:http://resthub.github.com/springmvc-router/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting matched router pattern?

balatbn opened this issue · comments

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}

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?

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!

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.