Spring MVC 流程
1. 检查是否为上传文件。
2. 通过HandlerMapping获取HandlerExecutionChain:
DispatcherServlet 中包含:handlerMappings ,
遍历获取正确的:HandlerMapping(RequestMappingHandlerMapping ) ,
具体的handlerMapping中包含:handlerMap ;
handlermap中为键值对:path = 对应的controller,例如:/hello/hello.htm=com.mumu.controller.HelloController@85a1ef
得到请求对应的HandlerExecutionChain,HandlerExecutionChain中包含:
1). interceptors:
2). 对应的controller实例
3. HandlerAdapter:
1). 将com.mumu.controller.HelloController@85a1ef传给获取适配器方法,遍历DispatcherServlet的handlerAdapters ,判断启用的是哪种Adapter,
继承Controller的还是注解的
2). 根据合适的Adater获取ServletHandlerMethodResolver:
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter@156b510 的 methodResolverCache:
{class com.mumu.controller.HelloController=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver@15c2d4e}
3). ServletHandlerMethodResolver,在它里面存储了方法和注解的关系
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver@15c2d4e
[public java.lang.String com.mumu.controller.HelloController.hello3(javax.servlet.http.HttpServletRequest)=[/hello3.htm], public java.lang.String
com.mumu.controller.HelloController.hello2(java.lang.String,org.springframework.ui.Model)=[/hello2.htm], public java.lang.String
com.mumu.controller.HelloController.hello(java.lang.String,java.util.Map)=[/hello1.htm],
public java.lang.String com.mumu.controller.HelloController.hello(java.lang.String)=[/hello.htm]]
4. 将上面信息汇总,反射调用方法,获取返回值
5. 返回值交给视图解析器去解析:InternalResourceViewResolver