Depth study SpringMVC framework

Most Java applications are Web applications, the presentation layer is an important part of WEB application can not be ignored .Spring to the presentation layer provides an excellent framework WEB Spring MVC.

About a pattern .MVC

MVC full name Model View Controller, the model (model) - view (view) - Abbreviation controller (Controller), and a software design model, with a service logic, data, a method of separating tissue interface display code, business logic to gather a member which, while improving and customization interfaces and user interaction does not need to rewrite the business logic. MVC was developed a unique structure for a conventional mapping input, processing and output of the logic functions in a graphical user interface.

  • : Create a Web application design patterns MVC is a (- - Model View Controller Model View Controller) using MVC
  • Model (model) represents the core of the application (such as a database record list).
  • View (View) display data (database record).
  • the Controller (controller) for input (write a database record).
  • MVC hierarchical grouping also simplifies development. Different developers can develop simultaneously view, controller logic and business logic.

Here Insert Picture Description

Two .SpringMVC Introduction

  • Spring MVC is a presentation layer framework, which is part of the Spring framework, for performing data exchange in view of the working layer.

Three .SpringMVC Features

  • ①Spring MVC framework does not know the view of the use,所以不会强迫开发者只使用 JSP 技术
  • ②Spring MVC separation of the role of controller, model objects, filters and handler object, such separation to make them easier to customize

IV. Principle parsing (often test interview)

Here Insert Picture Description

  • . 1, 客户端发出一个http请求给web服务器, Web servers parse the http request, if the request matches the path map DispatcherServlet (specified in web.xml), the request to the Web DispatcherServlet vessel.
  • 2, after receiving the request DipatcherServlet The information request (including the URL, Http method, the request header and request parameters Cookie, etc.) and HandlerMapping configuration 找到处理请求的处理器(Handler).
  • 3-4, DispatcherServlet HandlerMapping according to find the corresponding Handler, to the discretion Handler (Handler for the specific processing package) ,再由具体的HandlerAdapter对Handler进行具体的调用.
  • 5, Handler After the completion of the data processing返回一个ModelAndView()对象给DispatcherServlet。
  • 6, Handler returned ModelAndView () is just a logical view is not an official view,DispatcherSevlet通过ViewResolver将逻辑视图转化为真正的视图View。
  • 7、Dispatcher通过model解析出ModelAndView()中的参数进行解析最终展现出完整的view并返回给客户端

V. Component Description

  • DispatcherServlet: Front Controller

The front controller user request reaches the front end controller, it is equivalent mvc mode C, dispatcherServlet是整个流程控制的中心,由它调用其它组件处理用户的请求,dispatcherServlet的存在降低了组件之间的耦合性.

  • HandlerMapping: Processor mapper

处理器映射器HandlerMapping负责根据用户请求找到Handler即处理器, Springmvc mapper provides different ways to achieve different mapping.

  • Handler: Processor

Handler是继DispatcherServlet前端控制器的后端控制器,在DispatcherServlet的控制下Handler对具体的用户请求进行处理。Since Handler related to specific user service request, it is generally required Handler programmers based on business needs.

  • HandlerAdapter: Processor Adapter

通过HandlerAdapter对处理器进行执行,这是适配器模式的应用It may be performed by a processor of more types of expansion adapter.

  • View Resolver: view resolver

View Resolver负责将处理结果生成View视图, The Resolver View The first resolves the name into a physical view of the logical view name is the particular page address, then generates a view object View, View finally render the processing result to the user through display pages.

  • View: View

springmvc framework provides a lot of View view type of support.


VI. The core distributor DispatcherServlet

  • DispatcherServlet是Spring MVC的"灵魂"和"心脏"It is responsible for accepting HTTP requests and coordination of the various components of the job done SpringMVC request processing. And any Servlet, users must configure DispatcherServlet in web.xml.
  • (1) DispatcherServlet inheritance
    Here Insert Picture Description
  • (2) DispatcherServlet Introduction
  • DispatcherServlet is achieved Front Controller design pattern, providing centralized access point Spring Web MVC, and is responsible for the delegation of responsibility, and seamless integration with Spring IoC container, which can get all the benefits of Spring.
  • (3) DispatcherServlet main responsibilities

DispatcherServlet主要用作职责调度工作,本身主要用于控制流程

  • File upload parsing, if the request type is multipart file upload the MultipartResolver parsed;

  • By the HandlerMapping, maps the request to a processor (HandlerExecutionChain a return, comprising a processor, a plurality
    HandlerInterceptor interceptor);

  • By HandlerAdapter support multiple types of a processor (processor in HandlerExecutionChain);

  • ViewResolver logical view is achieved by parsing the name of the specific view;

  • Locale resolution;

  • Rendering a view of the specific and the like;

  • If you encountered in implementation exception to HandlerExceptionResolver to resolve.

  • (4) DispatcherServlet auxiliary class

  • DispatcherServlet spring used in some special bean REQUEST request to process and render the appropriate view. The bean is part of SpringMVC. You are able to use these special bean arranged in one or more of the WebApplicationContext. However, you do not need SpringMVC in the maintenance of these default bean to be used, to put those bean is not configured to initialize all had one.



  • The best investment is in yourself
    Here Insert Picture Description
  • 2020.03.28 记录辰兮的第39篇博客
Published 43 original articles · won praise 200 · views 40000 +

Guess you like

Origin blog.csdn.net/weixin_45393094/article/details/104843140