xpapad
xpapad

Reputation: 4456

Binding dot-separated Strings with @PathVariable in Spring MVC

I have the following method in my controller:

@RequestMapping( value="/servers/{server}", method = RequestMethod.GET )
public @ResponseBody List<Application> getServerInformation( String server ) {
    logger.debug( "Request for server: " + server );
    ...
}

When I request /servers/test.myserver.com, the bound variable has value test.myserver. In general, for any request that includes dot-separated values the last part is omitted from the bound variable's value. I am using Spring 3.0.4

Any suggestions?

Thanks

Upvotes: 8

Views: 5659

Answers (2)

aweigold
aweigold

Reputation: 6879

You can use Ant style matching patterns. For your example you can simply do this:

@RequestMapping( value="/servers/{server:.*}", method = RequestMethod.GET )
public @ResponseBody List<Application> getServerInformation(
                          @PathVariable(value = "server") String server ) {
    logger.debug( "Request for server: " + server );
    ...
}

Upvotes: 9

Aravind A
Aravind A

Reputation: 9697

You may want to change the useDefaultSuffixPattern of DefaultAnnotationHandlerMapping. Check How to change Spring MVC's behavior in handling url 'dot' character for a discussion on this.

Upvotes: 2

Related Questions