SPRINGMVC Study notes-@RequestMapping

Source: Internet
Author: User

@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]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.