[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.