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

0 Kudos
About the Author


Nov 29 - Dec 1
Discover 2016 London
Learn how to thrive in a world of digital transformation at our biggest event of the year, Discover 2016 London, November 29 - December 1.
Read more
Each Month in 2016
Software Expert Days - 2016
Join us online to talk directly with our Software experts during online Expert Days. Find information here about past, current, and upcoming Expert Da...
Read more
View all