Spring MVC------->version4.3.6-------->概述

              spring MVC

 1.概述:

    • spring web mvc(model-view-controller),实现了MVC架构模式,可以用于web application的开发  
    • spring web mvc 可以结合spring组织另外一个项目spring web flow(SWF),共同开发web application。
      • spring web flow用于处理(管理)web application page flow.
      • 也就是说spring web flow可以用于开发工作流类型的业务逻辑,所以当你的web application中需要开发工作流类型的业务逻辑时,你就可以在现有的project中直接加入spring web flow这个子工程,从而简化你的web application的开发过程

2.spring web MVC相对于其他MVC框架而言,有如下特点:

      • 除了实现明确的分层model-view-controller之外,spring MVC还将各个层的实现方式进一步解耦:将各层功能的实现进一步分成不同的组件,每种组件完成某一个方向的功能。 Each role — controller, validator, command object, form object, model object, DispatcherServlet, handler mapping, view resolver, and so on — can be fulfilled by a specialized object.  
      • 由于spring web MVC是基于spring framwork开发的,所以spring web MVC可以集成spring framework所拥有的一切功能,如方便的注解、IOC功能、AOP功能等等,所以使用spring MVC+spring framework进行web application的开发将会更加方便
      • 支持多种视图层技术:Customizable【可自定义的】 locale, time zone and theme resolution, support for JSPs with or without Spring tag library, support for JSTL, support for Velocity【速度】 without the need for extra bridges, and so on.
      • Chapter 43, spring JSP Tag Library提供了data binding and themes.功能
      • Chapter 44, spring-form JSP Tag Library使得JSP页面中编写form变得相对简单
      • WebApplicationContext container(s),前面已经讲过spring web MVC是基于spring framework搭建起来的,所以spring web MVC也有IOC容器的功能。spring framework中的IOC容器是BeanFactory对象或者ApplicationContext对象(常用后者),类似的,spring web MVC使用 WebApplicationContext来特别标识这是spring MVC模块的IOC容器。使用WebApplicationContext来管理spring web mvc下开发的相关beans,这些bean也有scope【有效范围】。 Section 7.5.4, “Request, session, global session, application, and WebSocket scopes”一章就讲解了spring MVC下编写的各个bean 的bean scope。

3.spring web MVC的工作原理

    • 配置好DispatcherServlet后, and a request comes in for that specific【特定的】 DispatcherServlet实例对象, 之后这个特定的 DispatcherServlet实例对象按照如下流程来处理接收到的请求:

      • step1,DispatchServlet对象接收request
      • step2,查找该DispatchServlet对象所对应的 WebApplicationContext,即[servlet-name]-sevlet.xml,
      • step3,将step2中查找到的WebApplicationContext作为请求的一个属性绑定到接收到的request上,使得controller and other elements in the process可以使用该WebApplicationContext中的beans. It is bound by default under the key DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE.
      • step4,根据controller中的定义,选择WebApplicationContext中相应的beans进行后续处理
          •    The locale resolver is bound to the request to enable elements in the process to resolve the locale to use when processing the request (rendering the view, preparing data, and so on). If you do not need locale resolving, you do not need it.
            • The theme resolver is bound to the request to let elements such as views determine which theme to use. If you do not use themes, you can ignore it.


        •          If you specify a multipart file resolver, the request is inspected for multiparts; if multiparts are found, the request is wrapped in a MultipartHttpServletRequest for further processing by other elements in the process. See Section 22.10, “Spring’s multipart (file upload) support” for further information about multipart handling.

        • An appropriate handler is searched for. If a handler is found, the execution chain associated with the handler (preprocessors, postprocessors, and controllers) is executed in order to prepare a model or rendering.

      • step5,If a model is returned, the view is rendered. If no model is returned, (may be due to a preprocessor or postprocessor intercepting the request, perhaps for security reasons), no view is rendered, because the request could already have been fulfilled.

4.spring web MVC涉及的知识点

学习的过程中总会得到一些心得体会,认真地将它们记录下来并分享给每一个愿意花费时间去阅读它们的人,然后意外地收获某个读者的评论,从而激发出新的感想,是一件十分令人欢快的事。如果你也在研习这方面的知识,欢迎加入到我们的队伍中来,和我们一起进步吧(^_^)
原文地址:https://www.cnblogs.com/lxrm/p/6480497.html