Introduction to Spring MVC

Source: Internet
Author: User

in the near future, Spring MVC has been developed, and it is integrated with spring, and a lot of things are not very understanding, so, in the online collation of information. In fact, spring MVC should be similar to STRUTS2 's role in the project, and the next figure will probably understand the principles of spring MVC!
Introduction to Spring MVC

Introduction to 1.Spring MVC

The Spring MVC Framework has an MVC framework that separates data, business, and presentation well by implementing the Model-view-controller pattern. From this perspective, Spring MVC is very similar to struts and Struts2. Spring MVC is designed around Dispatcherservlet, and Dispatcherservlet is responsible for distributing requests to specific handler. Process requests and go to corresponding views with configurable handler mappings, view resolution, locale, and theme resolution. The overall flow of Spring MVC request processing

A controller class is defined in spring3.x and must be marked with a @controller annotation. When the controller class receives a request, it looks for an appropriate processing method within itself to process the request. Use the @requestmapping annotation to map the method to a number of requests so that the method processes those requests. This method is like a method in a general class, and the method name parameter list and return value are not very restrictive like Struts2 frameworks. The method parameter list is specific and the return value is specific, which is not detailed here first. The purpose of this blog is to briefly describe how to quickly get started with the Spring MVC framework.

When a controller chooses a method that is appropriate for processing a request, the incoming request is passed in (depending on the type of the method parameter, it may be passed in with a different type), and the logic in the method is called for processing (or it can be called service to really handle). The method logic may also add or remove data from the parameter. When the processing method finishes processing, it is delegated to a view that handles the return value of the method. The return value of the handler does not represent the concrete implementation of the view, it can be just a string type, represents the view name, or even void (when spring MVC can find the default view based on the method name or the controller name). There's no need to worry that the return value is just the view name, and the view doesn't get the data you want to display. Because the method parameters are also available for the view. For example, if the processing method takes a map parameter, then the map can be obtained for the view as well.

The returned view name is returned to dispatcherservlet, which resolves the view name to a specific view implementation based on a view parser. The view parser here is a bean that implements the viewresolver excuse, and its task is to return a concrete implementation of the view (HTML, JSP, PDF, and so on).

Introduction to Spring MVC

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.