1) The most basic, method-level applications, such as:
1 @RequestMapping (value= "/departments") 2 public String Simplepattern ( { 3 4 System.out.println ("Simplepattern method was called"); 5 return "Someresult"; 6 7 }
When accessing Http://localhost/xxxx/departments, the Simplepattern method is called.
2) Parameter binding
1 @RequestMapping (value= "/departments") 2 public String finddepatment ( 3 @RequestParam ("DepartmentID") String DepartmentID) { 4 5 SYSTEM.OUT.PRINTLN ("Find Department with ID:" + DepartmentID); 6 return "Someresult"; 7 8 }
The form of access:/departments?departmentid=23 can trigger access to the Finddepatment method.
3) Rest-style parameters
1 @RequestMapping (value= "/departments/{departmentid}") 2 Public String Finddepatment (@PathVariable string departmentid) { 3 4 SYSTEM.OUT.PRINTLN ("Find Department with ID:" + DepartmentID); 5 return "Someresult"; 6 7 }
Like restful address access, such as:  /DEPARTMENTS/23, which is used (@PathVariable receive rest-style parameters
4) The 2 of the parameter binding form of rest style;
look at the example first, this is a bit like before:
1 @RequestMapping (value= "/departments/{departmentid}" " 2 public String finddepatmentalternative ( 3 @PathVariable (" DepartmentID ") String Somedepartmentid) { 4 5 System.out.println ("Find Department with ID:" + Somedepartmentid); 6 return "Someresult" ; 7 8 }
This is a bit different, is to receive a form such as/DEPARTMENTS/23 URL Access, the 23 as the incoming Departmetnid, but in the actual method finddepatmentalternative, using
@PathVariable ("DepartmentID") String Somedepartmentid, bind it to Somedepartmentid, so somedepartmentid here is 23
5) Multiple IDs are bound at the same time in the URL
1@RequestMapping (value= "/departments/{departmentid}/employees/{employeeid}") 2 PublicString Findemployee (3 @PathVariable String DepartmentID,4 @PathVariable String employeeId) { 5 6SYSTEM.OUT.PRINTLN ("Find Employee with ID:" + employeeId +7"From department:" +DepartmentID); 8 return"Someresult"; 9 Ten}
6) Support Regular expressions
1 @RequestMapping (value= "/{textualpart:[a-z-]+}.{ numericpart:[\\d]+} ") 2 public String regularexpression ( 3 @PathVariable String Textualpart, 4 @PathVariable String numericpart) { 5 6 System.out.println ("Textual part:" + Textualp Art + 7 ", numeric part:" + Numericpart); 8 return "Someresult" ; 9 }
For example, the following url:/sometext.123, then output: Textual Part:sometext, numeric part:123.
@requestmapping basic usage in Spring MVC