SpringMVC works of (turn)

SpringMVC the operating principle:

        

SpringMVC process

  1, the user sends a request to the front-end controller DispatcherServlet.

  2, DispatcherServlet HandlerMapping call processor receives a request mapper.

  3, the processor mappers find specific processor (depending on the configuration xml, notes to find), the object is generated processors and processor interceptors (if there is generated) together return to DispatcherServlet.

  4, DispatcherServlet call HandlerAdapter processor adapter.

  5, HandlerAdapter through specific adaptation call processor (Controller, also known as back-end).

  6, Controller execute complete return ModelAndView.

  7, HandlerAdapter the controller ModelAndView the results back to the DispatcherServlet.

  8, DispatcherServlet ModelAndView will pass ViewReslover view resolver.

  9, ViewReslover returns parsed particular View.

  10, DispatcherServlet render view (model data coming filled view) The View.

  11, DispatcherServlet user response.

Component Description:

  The following components are typically implemented using the framework provided:

  DispatcherServlet: a front-end controller, the control center of the entire process, other components of the control, unified, reducing the coupling between components, improve the scalability of each component.

  The HandlerMapping: ways to achieve different mapping by mapping extension processor, for example: profiles, to achieve interface mode, annotation methods. 

  HandlAdapter: by extending processor adapter to support more types of processors.

  ViewResolver: extended view by the parser, support more types of view resolution, for example: jsp, freemarker, pdf, excel like.

  Components:
  1, the DispatcherServlet front-end controller (not require engineers to develop), provided by the frame
  effect: receiving a request, a response result, corresponding to the repeater, the central processor. With dispatcherServlet reduces the coupling between the other components.
  A user request arrives at the front end of the controller, it is equivalent mvc mode c, dispatcherServlet center of the entire process is controlled by the other components of the processing which calls the user's request, the presence DispatcherServlet reduces coupling between components.

  2, the processor HandlerMapping mapper (not require engineers to develop), provided by the frame
  effect: The Handler lookup request url
  HandlerMapping i.e. Handler responsible for finding processor upon user request, provides SpringMVC mapper different ways to achieve different mapping, e.g. : profiles, to achieve interface mode, annotation methods.

  3, the adapter processor HandlerAdapter
  effect: according to a specific rule (rule HandlerAdapter required) to perform Handler
  for execution by the processor HandlerAdapter, which is an application of the adapter mode, the processor may be more types of expansion performed by the adapter.

  4, processor Handler (required engineers to develop)
  Note: do HandlerAdapter accordance with the requirements of the preparation Handler, so that the adapter can go to the correct execution Handler
  Handler is the second back-end DispatcherServlet front controller, under the control of the DispatcherServlet Handler specific user requests are processed.
  Since Handler related to specific user service request, it generally requires engineers to develop Handler according to business needs.

  5 viewresolver View Resolver (not require engineers to develop), provided by the frame
  effect: parsing a view, according to the logical view name resolves to a real view (View)
  View is responsible for processing the Resolver View to generate the results, according to the first logic View the Resolver view name to a physical view of a particular name is the address of the page, then the view object generates view, view finally render the processing result to the user through display pages. springmvc View framework provides many types of views, comprising: jstlView, freemarkerView, pdfView like.
  You need to model data show generally by page or tag page by page template technology to users, engineers need to develop a specific page based on business needs.

  6, view View (required engineers to develop ... JSP)
  View is an interface, implementation class support different types of View (jsp, freemarker, pdf ...)

  Core architecture specific process steps are as follows:
  1, the first user sends a request -> after DispatcherServlet, the front controller receives a request that they are not treated, but the commission process to other parsers, as a unified access point, the globally process control;
  2, the DispatcherServlet -> the HandlerMapping, the request will be mapped to the HandlerMapping HandlerExecutionChain object (Handler comprising a processor (page controller) object, a plurality of interceptors HandlerInterceptor) object, such a strategy mode, it is easy to add the new mapping strategies;
  3, the DispatcherServlet -> HandlerAdapter, HandlerAdapter will the processor packaging for the adapter to support multiple types of processors, namely the application of design patterns adapter, making it easy to support many types of processors;
  4 , HandlerAdapter -> function call processing method of a processor, will be called HandlerAdapter is adapted according to the result of the real functionality of the processor processing method, the processing completion; ModelAndView object and returns a (comprising model data, logic View name);
  . 5, a logical view ModelAndView name -> ViewResolver, ViewResolver name will resolve to a particular logical view View, this strategy mode, it is easy to replace other view technologies;
  . 6, View -> Render, View will be passed in accordance with the model data to render model, model Map here is actually a data structure, it is easy to support the other view technologies;
  7, returns control to the DispatcherServlet, DispatcherServlet response returned by the user, this flow ends a .

  We need to develop under normal circumstances the following two components:

  Handler: a processor that is represented by the back-end controller.

  View: view, i.e., displayed to the user interface, typically a label view showing language model data.

 

  In the prior SpringMVC let's look at what is MVC pattern

  MVC: MVC is a design pattern

  MVC schematics:

         

  analysis:

  Model M-Model (complete business logic: YES javaBean configuration, service + dao + entity)

  V-View view (do interface display jsp, html ......)

  C-Controller The controller (reception request -> call model -> distributed according to the result page)

  What springMVC is: 

  springMVC is an open-source MVC framework, springMVC = struts2 + spring, springMVC plus the equivalent of Struts2 integration sring, but there is a doubt that, springMVC and spring is what to do with it? This has a good explanation on Baidu Encyclopedia: mean, springMVC spring is a follow-up product, in fact, spring based on the original, but also provides a MVC web application module can be simply understood as the springMVC spring one module (similar to AOP, this module IOC), the network often say springMVC seamless integration and spring, spring is in fact springMVC of a sub-module, so there is no need to integrate with the spring.

  SpringMVC schematics:

        

 

  See the map you may have a lot of doubts, and now we look at this map :( step can be understood in comparison MVC schematic)

  The first step: the user initiates a request to the front end controller (the DispatcherServlet)

  Step Two: front-end controller processor request mapper (HandlerMappering) to find the processor (the Handle): xml configuration or annotation by lookup

  The third step: After finding processor mapper (HandlerMappering) as the front controller returns execution chain (HandlerExecutionChain)

  第四步:前端控制器(DispatcherServlet)调用处理器适配器(HandlerAdapter)去执行处理器(Handler)

  第五步:处理器适配器去执行Handler

  第六步:Handler执行完给处理器适配器返回ModelAndView

  第七步:处理器适配器向前端控制器返回ModelAndView

  第八步:前端控制器请求视图解析器(ViewResolver)去进行视图解析

  第九步:视图解析器像前端控制器返回View

  第十步:前端控制器对视图进行渲染

  第十一步:前端控制器向用户响应结果

  看到这些步骤我相信大家很感觉非常的乱,这是正常的,但是这里主要是要大家理解springMVC中的几个组件:

  前端控制器(DispatcherServlet):接收请求,响应结果,相当于电脑的CPU。

  处理器映射器(HandlerMapping):根据URL去查找处理器。

  处理器(Handler):(需要程序员去写代码处理逻辑的)。

  处理器适配器(HandlerAdapter):会把处理器包装成适配器,这样就可以支持多种类型的处理器,类比笔记本的适配器(适配器模式的应用)。

  视图解析器(ViewResovler):进行视图解析,多返回的字符串,进行处理,可以解析成对应的页面。

Guess you like

Origin www.cnblogs.com/jing99/p/11462980.html