Spring MVC 是一个对javaWeb中Servlet 简化和封装,
1.首先SpringMVC 配置DispatcherServlet 来接受所有的请求,我们通过DispatcherServlet 响应的所有数据,DispatcherServlet 是HttpServlet的子类,他的所有方法(Get,Post…)最终都会执行doDispatch方法
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) {}
2.根据用户的输入url通过SpringMVC handlerMapping组件 找到对应的 HandlerExecutionChain 执行链
mappedHandler = this.getHandler(processedRequest);
3.找到handler 适配的HandlerAdapter
HandlerAdapter ha = this.getHandlerAdapter(mappedHandler.getHandler());
4.执行所有注册拦截器的preHandler方法
if (!mappedHandler.applyPreHandle(processedRequest, response)) {
return;
}
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
6.倒序执行所有注册拦截器的postHandler方法
mappedHandler.applyPostHandle(processedRequest, response, mv);
7.请求视图解析和视图渲染,如果是jsp就返回jsp页面,如果是 被@ResponseBody就返回JSON数据
this.processDispatchResult(processedRequest, response, mappedHandler, mv, (Exception)dispatchException);