Tag: expr das Print Value expression regular people size color
1. Application at the method level:
1 @RequestMapping (value= "/department")23 public String Simpledapatment () {45 System.out.println (""); 6 return ("result"); 7
When accessing Http://localhost/XXXX/department, call the Simpledepatment method.
2. Parameter binding
@RequestMapping (value= "/department") public string Finddepartment (@RequestParaam (DepartmentID) string departmentid) {System.out.println ("Asasadas"); return ("Someresult");}
Visit http://localhost/XXXX/department?departmentId=22 to start the finddepartmentf method.
3, REST-style parameters
1 @RequestMapping (value= "/department/{departmentid}")23 Public String Find (@PathVariable string departmentid) {45 System.out.println ("ASA"); 6 7 return "Somerequest"; 8 9 }
Access HTTP://LOCALHOST/XXXX/DEPARTMENT/22, @PathVariable receive rest-style parameters
4, REST-style parameters 2
1 @RequestMapping (value= "/department/{depatmentid}") 2 3 Public String Finddepartment (@PathVariable (DepartmentID) string somedepartmentid) 4 5{ 6 7 Syso; 8 9 Retrrn "SDS"; Ten One}
Access to HTTP://LOCALHOST/XXXX/DEPARTMENT/22, the difference is that 22 was uploaded to DepartmentID, but in the actual method Finddepartment (@PathVariable (DepartmentID) String somedepartment),
Bind it to somedepartment, so Somedepartment is 22.
5. URL binding multiple IDs
1@RequestMapping (value= "/user/{userid}/admin/{adminid}")2 3 PublicString Findpeople (4 5 @PathVariable String userId,6 7 @PathVariable String Adminid) {8 9SYSO ("Userid+adminid");Ten One return"SDFs"; A -}
6. Support 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.
@requestmapping basic usage of Spring MVC