Today, you need to write an interface, after writing, testing the line has been reported 404 errors, do not know why the error. Should be a GET request address problem, GET request has two parameters, the time to change to a parameter is good, perhaps that way is not suitable for writing two parameters of Get request it.
Mode one: GET request a parameter
@RequestMapping ("/testpathvariable/{id}") public String testpathvariable (@PathVariable (value= " ID ") Integer ID) { System.out.println (" testpathvariable: "+ ID); return SUCCESS;}
URL Request Address: http://localhost:8080/testPathVariable/001
Page output: testpatvariable:001
Mode two: Get request multiple parameters (2)
@RequestMapping (value= "/testrequestparam") Public
@RequestParam (value= "age", required=falseint -age ) { System.out.println (" Testrequestparam "+" Username: "+ username +" Age: "+ age); return SUCCESS;}
URL Request Address: http://localhost:8080/testRequestParam?username=jackie&age=12
Page output: Teatrequestparam username:jackie age:12
Spring annotations
1. How spring MVC matches the request path
@RequestMapping are used to map requests, such as GET requests, post requests, or restful and non-restful styles.
This annotation can be used on a class or on a method, if used on a class, to represent the parent path of all methods in that class.
2. How spring MVC gets the requested parameters
@PathVariable This annotation is used to map placeholders for bindings in the request URL. By @pathvariable, you can bind the parameters of placeholders in URLs to the arguments of the controller processing method.
@RequestParam The annotation is also used to get the request parameters.
SPRINGMVC GET request and its request address notation