@RequestMapping annotations

Source: Internet
Author: User

@RequestMapping annotations
Developers need to develop appropriate processing methods for each request action within the controller. The org.springframework.web.bind.annotation.RequestMapping annotation type indicates which class or method spring uses to process the request action, which can be used for classes and methods.
@RequestMapping can be used to annotate a controller class, in which case all methods are mapped to requests relative to the class level, indicating that all requests processed by the controller are mapped to the path indicated by the Value property. The sample code is as follows:

  @Controller @requestmapping (value  = "/user"   public  class   usercontroller{@RequestMapping (value  = "/register" )  public    String Register () { return  "register" ; } @RequestMapping (Value  = "/login"  public   String login () { return  "Login"  Span style= "COLOR: #000000" >; }}

Because the Usercontroller class adds a @requestmapping annotation for value= "/user", all related paths are added "/user", and the method is mapped to the following request URL (Uniform Resource Locator):
Http://localhost:8080/user/register
Http://localhost:8080/user/login
Use the @requestmapping annotation to specify the properties shown in the following table:

Property Type Whether it is necessary Description
Value String[] Whether Used to map the actual address of the specified request to the method
Name String Whether Specify an alias for the mapped address
Method Requestmethod[] Whether MAP Specifies the type of method requested, including get, POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE
Consumes String[] Whether Specifies the type of submission to process the request (Content-type), such as Application/json, text/html, and so on
Produces String[] Whether Specifies the type of content returned, and the content type that is returned must be the one contained in the request header (Accept)
Params String[] Whether Specifies that some parameter values must be included in the request for the method to handle
Headers String[] Whether Specifies that some specified header values must be included in the request for the method to process requests
Path String[] Whether In a servlet environment only: URI path mappings (for example: "/mypath.do"). At the method level, relative paths are supported (for example: "Edit.do")

@RequestMapping annotations

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.