JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Spring MVC URI Template Patterns using Regular Expressions


In the previous example you have seen " How to map URLs using annotations". In this example you can see how to use regular expressions as part of URI.

The @RequestMapping annotations supports the use of regex in URI template variables. The syntax is {varName:regex} where the first part defines the variable name and the second is the regular expression.

The following example shows a controller in a Spring MVC application that uses @RequestMapping annotation with regex support:

@RequestMapping(value = "/java/{libName:[a-zA-Z\\-]+}-{version:\\d\\.\\d\\.\\d}", 
			method = RequestMethod.GET)
public void handleDownloads(@PathVariable String libName, @PathVariable String version){
		
	System.out.println("libName: "+libName);
	System.out.println("version: "+version);
	
	// your business logic
}

<< Previous Program 

Spring MVC Framework Examples

  1. Spring MVC hello world example
  2. Spring MVC REST hello world example
  3. How to map URLs to beans in Spring MVC?
  4. How to map URLs using annotations in Spring MVC?
  5. Spring MVC URI Template Patterns using Regular Expressions
Knowledge Centre
Transient and Volatile Modifiers
Transient: The transient modifier applies to variables only and it is not stored as part of its object's Persistent state. Transient variables are not serialized.

Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
Famous Quotations
Discipline is just choosing between what you want now and what you want most.
-- Unknown Author

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.