How to use SPRINGMVC---requestmapping annotation classes

Source: Internet
Author: User

Use of requestmapping annotations

    1. Develop the controller class, use @controller annotation annotations, and scan the corresponding package path with <context:component-scan/> in the configuration file. You can use the Controller class to handle HTTP requests, and you can create an unequal number of controllers to handle different business logic requests, respectively. Dispatcherservlet intercepts the request, it is possible to determine the processing method for the request through the mapping information provided by the @requestmapping on the controller
    2. @requestmapping annotations can be annotated at the class definition and method definitions of the Controller class. The requestmapping at the class definition provides preliminary request mapping information, and the requestmapping at the method provides further subdivision mapping information. requestmapping annotation class attributes, respectively, value, method, consumes, produces, params, headers
      • Value: represents the specific request path, for example, Login,/user is value, if not with other attributes, value can be omitted;
      • Method: Specifies the requested method type, Requestmethod.get, post, put, delete, etc., by default, without this property, indicating that any request type can be received. The method property can be an array ({requestmethod.get, requestmethod.post});
      • Consumes: Specifies the requested commit content type (Content-type), the property value Application/json,text/html,text/plain. The property value can be an array;
      • Produces: Specifies the type of content returned, and the property value is consistent with consumes. Text/plain represents the text type;
      • Params: Specifies that certain parameter values must be included in the request to trigger this processing. For example, params= "Myparam=myvalue" indicates that a myparam=myvalue is included in the request before it is triggered. parameter in addition to using the = number, you can also use! = number, which means that the method is triggered when the value of the parameter is not equal, or it can be used without specifying a specific value, directly using the paramname format, and the parameter named ParamName must be included on behalf of the request; ParamName format indicates that a request cannot contain a request parameter named ParamName
      • Headers: The request header header must contain some specified parameter values for the method to process the request. For example headers= "content-type=text/*"

Define ant style and URLs with placeholders

@RequestMapping not only supports standard URLs, it also supports Ant-style and URLs with {XXX} placeholders, such as URLs that are legal:

/user/*/login: Match/user/any character (string)/login;

/user/**/login: Match/user/login,/user/aaa/bbb/login,/user/any character (string)/login;

/user/login?? : Match/user/loginaa

Placeholder/user/{userid}: Where userId can replace any character

How to use SPRINGMVC---requestmapping annotation classes

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.