For example, with the URL
foo.com/bar/99
99 will be available directly to a method in the controller as an argument. The controller is mapped to /bar
For anyone familiar with ASP.NET MVC or Django, this would be similar to routes.MapRoute in the former and using (?P\d+) in urlpatterns in the latter.
It would be possible to process the data in the Http Request object directly to get this, but I’d like to know if Spring MVC has built-in support for this (particularly version 2.5).
No, Spring does not support this out of the box. You can, however, map path to method name using @RequestMapping and appropriately configured
InternalPathMethodNameResolver:You’ll have to specify
prefixforInternalPathMethodNameResolveras “do” for the above to work since method names can’t begin with digit. If you were to use “foo.com/bar/baz” as URL and call your methodbaz, no additional configuration would be necessary.If you don’t want to use method name mapping, getting ’99’ as parameter is as easy as grabbing it from
request.getPathInfo()in your method.