In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you the "SpringMVC implementation steps and the use of Model sample analysis", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "SpringMVC implementation steps and the use of Model sample analysis" this article.
The first SpringMvc HelloWorld no startup class
Only springboot has startup class.
Front-end operation
Visit the project name to go to the default home page and display a link
Click the link and request helloWorld.do to jump to another jsp page
Perform steps in the background
* also corresponds to the RequestMapping of controller. To map multiple requests, it is /.
Web.xml is responsible for intercepting requests and distributing them to controller for processing
Spring-mvc.xml is responsible for parsing the return value of controller and jumping to the appropriate page.
Spring-mvc.xml and the declaration in web.xml can be replaced by Java Configuration
Project example: eclipse/SpringMvc01
Introduction to the second SpringMvc project
Visit the home page and ask the background controller to initialize the student list. After loading the ModelAndView, return to list.jsp to display the student list.
List.jsp clicks the "add students" link to request the background controller,controller processing page to jump to add.jsp.
List.jsp clicks the "modify" operation, takes the student id parameters to the background controller for processing, and controller calls up the id student information, encapsulates it in ModelAndView and returns to the update.jsp page.
Knowledge point integration
SpringMvc object properties are automatically encapsulated. See add.jsp.
SpringMvc garbled resolution: configure a filter. See web.xml.
SpringMvc redirection and forwarding: forwarding can take parameters, but the URL bar will not change, the redirection will change. See StudentController
SpringMvc support for servlet API: support for request, response, etc. See UserController.
SpringMvc automatically parses json: introduces jar packages, namespaces, and annotations. See UserController.
Code example: SpringMvc02SpringMvc support for rest style url
Features: requests for any controller do not have a .do suffix, request front-end pages do not have .jsp; all url have no suffix (but bloggers seem to support the .html suffix).
@ PathVariable gets the url parameter.
Mapping of SpringMvc to static Resources
Code example: SpringMvc5Rest
SpringMvc file upload
Introduce jar package, configure bean
SpringMvc file upload
Quote jar package and configure bean
Single file upload
Multiple file upload
Code example: SpringMvc6FileUpload
Diagram the execution flow of SpringMvc
1. The user initiates a request to the front controller DispatcherServlet
Front controller springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:ApplicationContext.xml 1 springmvc /
two。 The front controller sends url to request processor mapper HandlerMapping to find Handler based on url
3. The processor mapper returns an execution chain to the front-end controller
4. The front-end controller requests the processor adapter to Handler
5. Processor adapter choose the appropriate processor (Handler is usually controller)
The controller controller returns the ModelandView and the view name
/ / accept the request with the path name H2 @ RequestMapping ("/ H2") public String hello (Model model) {/ / return the content Hello,SpringMvc with the parameter name msg to the hello page parsed by the view parser model.addAttribute ("msg", "Hello,SpringMvc"); return "hello"; / / it will be processed by the view parser} / / here I use Model
6.Handler returns the ModelAndView to the processor adapter
7. The processor adapter returns the ModelAndView to the front controller
8. The front-end controller requests the view parser View resolver to parse the view according to the logical view to add prefixes and suffixes to the real physical view (jsp, etc.)
9. The view parser returns view to the front-end controller
10. Render the view to populate the model data into the request field
11. Response view
Front-end controllers, processor mappers, processor adapters do not require us to write
The processor needs us to write (usually Controller)
The above is all the contents of the article "SpringMVC implementation steps and sample Analysis using Model". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.