[2] spring mvc Study Notes

Source: Internet
Author: User

[2] spring mvc Study Notes

The method described above is the most basic and original method.

When multiple operations such as addition, deletion, modification, query, and so on occur, it is not very convenient to use. Therefore, annotations are used for development (a url corresponds to a controller)

Basic Steps

1. Import required packages

2. Configure the web. xml file. All processing is handled by DispatcherServlet.

3. spring-servlet.xml

Annotation development is used here

(1) it will automatically scan the class file under com. qzp. web;

(2) The view parser parses the view and adds the prefix and suffix.

 
 
  
  
  
   
   
  
 

4. Controller

Several Notes (1) @ controller declares that it is a controller; (2) @ RequestMapping declares the url corresponding to this method for processing; (3) Finally, return the view name, together with the prefix and Suffix in the view parser, it determines the page to jump.

Package com. qzp. web; import org. springframework. stereotype. controller; import org. springframework. web. bind. annotation. requestMapping; @ Controllerpublic class MyFirstController {// RequestMapping indicates the url used to correspond to @ RequestMapping ({"/hello", "/"}) public String helloWorld () {System. out. println ("first spring mvc"); // This is the view name return "hello";} // a controller can map multiple @ RequestMapping ("/hello ") public String welcome () {return "welcome ";}}

5. hello. jsp is under WEB-INF/jsp/

Annotation-based spring mvc

When the url value "hello" is accessed, it is handled by MyFirstController. MyFirstController returns "hello", which is processed by the view parser, adds the prefix and suffix, and finally returns the result to the user.


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.