Software Developers
Showing results for 
Search instead for 
Do you mean 

Using Regular Expressions to Evaluate Path Variables in a Spring MVC controller

amirkibbar on ‎04-22-2013 10:47 PM

Sometime you may want to process the URI in the request and assign values to several path variables instead of a single one. This can easily be achieved with regular expressions on the URI itself within the @RequestMapping.


The syntax is {varName:regex} for the parsed URI path variable. For example suppose we want to provide an HTTP GET over this URI: /jars/log4j-1.2.16.jar, but we want to allow any jar name, version and extension with the format name-version.extension and we also want to get each of these path variables in a separate argument in our controller handler method. We can do it this way:



public final class MyController {
     public void handle(@PathVariable String artifact, @PathVariable String version, @PathVariable String extension) {

 Simple and useful.


Post author: Amir Kibbar

About the Author


Leave a Comment

We encourage you to share your comments on this post. Comments are moderated and will be reviewed
and posted as promptly as possible during regular business hours

To ensure your comment is published, be sure to follow the Community Guidelines.

Be sure to enter a unique name. You can't reuse a name that's already in use.
Be sure to enter a unique email address. You can't reuse an email address that's already in use.
Type the characters you see in the picture above.Type the words you hear.
1-3 December 2015
Discover 2015 London
Discover 2015 in London, the ultimate showcase technology event for business and IT professionals to learn, connect, and grow.
Read more
November 2015
Software Online Expert Days
Join us online to talk directly with our Software experts.
Read more
View all