Spring MVC Fundamentals Article 1

Source: Internet
Author: User
Tags class definition

Spring MVC Basics @RequestMapping Request mapping using [email protected] Annotations

(1) Specifies that the controller or method can handle those URL requests.

(2) Scope of application: The class definition or the method definition can be added.

(3) Adding the annotation at the class definition is relative to the root of the Web app, and at the method is a further refinement of the request processing defined by the class. You can not add the annotation on the class definition, but the annotation is on the method definition, at which point the URL of the note tag at the method is relative to the web App root.

(4) Thinking: If I do this function, I will scan all the annotations on the controller layer when the application is started, then initialize the annotations to a map collection, and then follow through the URL to the map to query the specific controller. ( personal ideas, concrete implementation without research source, do not know )

[email protected] Detailed mapping of request parameters, request methods, and request headers

The request can be mapped in more detail through @requestmapping, ensuring that only requests that meet the requirements can be entered into the controller. The @RequestMapping contains a mapping condition with value (request URL), method (which can be accessed by request, such as GET, post, and so on), params (the matching field for the request parameter), heads (Request header). These mapping conditions can be used in combination to make the request more granular.

(1) A @requestmapping to control the request mode slightly

@RequestMapping (value= "/helloworld", method = public String Hello () {      System.out.println ( "Hello World");       return "Success";}

(2) @requestmapping to control the request parameters and the request header

Working with instances

[Email protected] supports wildcard URL matching

Use case

Spring MVC Fundamentals Article 1

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.