@RequestMapping modifier Classes
@RequestMapping ("/SPRINGMVC")//This path is the path relative to the Web App root directory @controllerpublic class springmvctest { private static final string success = "SUCCESS"; /** * @RequestMapping In addition to the cosmetic method, you can also decorate the class * class definition: Provide preliminary request mapping information, Relative to the web app's root * method: Provides further subdivision mapping information * @return */ //at this time the request should be written as http://localhost:8080/SpringMVC/springmvc/ testrequestmapping @RequestMapping ("/testrequestmapping")//This path is relative to the class above the annotated path public string testrequestmapping () { system.out.println ("testrequestmapping"); return SUCCESS;
Specify the request method for @requestmapping
/** * Use method to specify the request method * @return *///at this time through the Http://localhost:8080/SpringMVC/springmvc/testMethod request is invalid, Must be a POST request to respond to @requestmapping (value= "/testmethod", method=requestmethod.post) public String TestMethod () { System.out.println ("TestMethod"); return SUCCESS;}
Specify request parameters and request headers for @requestmapping
http://localhost:8080/SpringMVC/springmvc/testParamsAndHeaders?username=admin&age=10 this way HTTP Status 404// http://localhost:8080/SpringMVC/springmvc/testParamsAndHeaders?username=admin&age=11 This way you can access @requestmapping (value= "Testparamsandheaders", params={"username", "age!=10"}, headers={"accept-language= zh-cn,zh;q=0.8 "}) public String testparamsandheaders () {return SUCCESS;}
@RequestMapping Match Ant Path
http://localhost:8080/SpringMVC/springmvc/testAntPath/aa/abc//@RequestMapping ("/testantpath/*/abc")//* denotes any character HTTP://LOCALHOST:8080/SPRINGMVC/SPRINGMVC/TESTANTPATH/A/ABC//@RequestMapping ("/TESTANTPATH/?/ABC")//? Represents any one character//http://localhost:8080/springmvc/springmvc/testantpath/a/45/abc@requestmapping ("/testAntPath/**/abc") * * Indicates matching multilayer path public String Testantpath () {System.out.println ("Testantpath"); return SUCCESS;}
@pathvariable Annotations for @RequestMapping
/** * @PathVariable Map the placeholders in the URL to the parameters of the target method * @param ID * @return *///http://localhost:8080/springmvc/springmvc/ Testpathvariable/45@requestmapping ("/testpathvariable/{id}") Public String testpathvariable (@PathVariable ("id") Integer ID) {System.out.println ("testpathvariable:" + ID); return SUCCESS;}
This article is from "Avatar" blog, please make sure to keep this source http://shamrock.blog.51cto.com/2079212/1602513
SPRINGMVC study notes [email protected]