SpringMVC工作原理解读
spring mvc,框架,SpringMVC原理2016-07-22
The Spring Web model-view-controller (MVC) framework is designed around aDispatcherServlet
that dispatches requests to handlers, with configurable handlermappings, view resolution, locale,
time zone and theme resolution as well as support foruploading files. The default handler is based on the
@Controller
and @RequestMapping
annotations, offering a wide range of flexible handling methods. With the introductionof Spring 3.0, the
@Controller
mechanism also allows you to create RESTful Web sitesand applications, through the
@PathVariable
annotation and other features.
SpringWeb MVC框架是围绕着DispatcherServlet来设计的,其中DispatcherServlet分发请求给处理器,SpringMVC具有可配置的映射、视图解析、区域设置、时区设置和主题解析以及上传图片文件的支持等特性。默认的处理器基于@Controller注解和@RequestMapping注解,它提供了灵活的处理方法。在Spring3.0中,@Controller机制结合@PathVariable注解以及其他的特征使得他允许创建支持RESTful风格的Web站点和应用。
下面的图给出了其运行的主要流程
访问的流程解析
基本步骤:
1. Http请求提交到Tomcat后,读取web.xml中的配置,将请求交给DispatcherServlet处理.
2. DispatcherServlet根据Spring容器中的HandlerMapping查找处理器。
3. 调用处理器,完成业务方法,返回ModelAndView
4. 通过视图解析器查找到ModelAndView所代表的视图。
5. 将数据以Model的方式,填充到上一步中获取到的视图中去,完成整个的视图的构造。
6. 将得到的视图整体返回给请求方,通过web浏览器解析后呈现出来。