SpringMVC: What is SpringMVC

What is SpringMVC

Outline

1570166394812.png

Spring MVC is part of the Spring Framework is based on a lightweight Java implementation of MVC Web framework.

View the official document: https://docs.spring.io/spring/docs/5.2.0.RELEASE/spring-framework-reference/web.html#spring-web

Why should we learn SpringMVC it?

Spring MVC features:

  1. Lightweight, easy to learn
  2. Efficient, MVC-based request response frame
  3. Spring and compatibility, and seamless integration
  4. Convention over configuration
  5. Powerful: RESTful, data validation, formatting, localization, themes, etc.
  6. Simple and flexible

Spring's web framework around the DispatcherServlet  [dispatch Servlet] design.

DispatcherServlet role is to distribute requests to different processors. Starting Spring 2.5, users use Java 5 or later can be used to develop annotation based form, it is very simple;

Because of good SpringMVC, simple, convenient, easy to learn, born and Spring seamless integration (using SpringIoC and Aop), using the convention over configuration. Junit can perform simple test. Restful support style exception handling, localization, internationalization, data validation, type conversion, interceptors and so on ...... so we have to learn.

The most important point is with more people, companies use more.

The central controller

DispatcherServlet designed around the Spring web framework. DispatcherServlet role is to distribute requests to different processors. Starting Spring 2.5, users of Java 5 or later can use annotation-based controller declaratively.

Spring MVC framework, like many other MVC frameworks,  request-driven  ,  around a central dispatching Servlet request and provide other functions , the DispatcherServlet is an actual Servlet (it inherits from HttpServlet base class) .

1570167567494.png

SpringMVC principle as shown below:

When the initiation request is intercepted request to upstream controller, depending on the request to generate the proxy request corresponding to the request to find the actual controller, the controller processing the request, creating a data model, access to the database, the model response to the central controller, rendering controller model and view the results of the view, the results are returned to the central controller, then the result returned to the requestor.

1570167624269.png

SpringMVC implementation of the principle of

1570167751381.png

The picture shows a flowchart SpringMVC more complete, a solid line indicates SpringMVC framework technology does not require developers to implement, it requires developers to implement the dotted line.

A brief analysis of the implementation process

  1. It represents DispatcherServlet front controller, the whole SpringMVC control center. Requesting user, DispatcherServlet receives the request and interception request.

    • We assume that the request url is:  HTTP: // localhost : 8080 / SpringMVC / the Hello
    • As url split into three parts:
    • HTTP: // localhost : 8080 Server domain
    • SpringMVC deployed on the server's web site
    • hello indicates that the controller
    • Analysis, as described above url: Request a server located localhost: hello controller on site SpringMVC 8080.
  2. HandlerMapping processor mapping. DispatcherServlet call HandlerMapping, HandlerMapping url look Handler upon request.
  3. HandlerExecution shows a specific Handler, its main role is to find a controller according to url, url be searched as controller: hello.
  4. HandlerExecution transmitting the analysis information to DispatcherServlet, mapping controller resolver.
  5. HandlerAdapter adapter indicates that the processor, which performs Handler to specific rules.
  6. Handler let specific Controller to perform.
  7. Controller The specific implementation information back to HandlerAdapter, such ModelAndView.
  8. The view logic HandlerAdapter or model name passed to DispatcherServlet.
  9. DispatcherServlet call the view resolver (ViewResolver) to resolve the logical view name HandlerAdapter transfer.
  10. View resolver resolves the logical view name passed DispatcherServlet.
  11. According DispatcherServlet view results view parser, call the specific view.
  12. The final view presented to the user.

Guess you like

Origin www.cnblogs.com/wwjboke/p/12486429.html