您的位置:首页 > 编程语言 > Java开发

SpringMVC工作原理解读

2016-07-21 22:06 585 查看
The Spring Web model-view-controller (MVC) framework is designed around a
DispatcherServlet
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站点和应用。

下面的图给出了其运行的主要流程


[b]


[/b]

访问的流程解析







基本步骤:

1. Http请求提交到Tomcat后,读取web.xml中的配置,将请求交给DispatcherServlet处理.

2. DispatcherServlet根据Spring容器中的HandlerMapping查找处理器。

3. 调用处理器,完成业务方法,返回ModelAndView

4. 通过视图解析器查找到ModelAndView所代表的视图。

5. 将数据以Model的方式,填充到上一步中获取到的视图中去,完成整个的视图的构造。

6. 将得到的视图整体返回给请求方,通过web浏览器解析后呈现出来。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息