1) The most basic, method-level applications, such as:
@RequestMapping (value= "/departments") public String Simplepattern () { System.out.println ("Simplepattern method was called"); return "Someresult";}
When accessing Http://localhost/xxxx/departments, the Simplepattern method is called.
2) Parameter binding
@RequestMapping (value= "/departments") public String finddepatment ( @RequestParam (" DepartmentID ") String DepartmentID) { System.out.println (" Find Department with ID: "+ DepartmentID); c7/>return "Someresult";}
The form of access:/departments?departmentid=23 can trigger access to the Finddepatment method.
3 Rest-style parameters
@RequestMapping (value= "/departments/{departmentid}") public String finddepatment (@ Pathvariable String departmentid) { System.out.println ("Find Department with ID:" + DepartmentID); return "Someresult";}
Like a restful address, such as:/DEPARTMENTS/23, which is used (@PathVariable receive rest-style parameters
4 Rest-style parameter binding form 2
@RequestMapping (value= "/departments/{departmentid}") public String finddepatmentalternative ( @PathVariable ("DepartmentID") String somedepartmentid) { System.out.println ("Find Department with ID: "+ Somedepartmentid); return "Someresult";}
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, which is bound to
Somedepartmentid, so the somedepartmentid here is 23.
5 multiple IDs are bound at the same time in the URL
@RequestMapping (value= "/departments/{departmentid}/employees/{employeeid}") public String Findemployee ( @PathVariable string DepartmentID, @PathVariable string employeeId) { System.out.println ( "Find employee with ID:" + employeeId + "from Department:" + DepartmentID); return "Someresult";}
6 Support for regular expressions
@RequestMapping (value= "/{textualpart:[a-z-]+}.{ numericpart:[\\d]+} ") public string RegularExpression ( @PathVariable string Textualpart, @PathVariable String Numericpart) { System.out.println ("Textual part:" + Textualpart + ", numeric part:" + Numericpart); return "Someresult";}
For example, the following url:/sometext.123, the output:
Textual Part:sometext, numeric part:123.
Summary of 6 basic usages of @requestmapping in Spring MVC