SpringMVC之HandlerMapping源码分析
2024-08-30 10:35:19
01.doDispatch方法中代码如下:
HandlerExecutionChain mappedHandler=this.getHandler(processedRequest) 02.DispatcherServlet类中 找到getHandler()
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
Iterator var2 = this.handlerMappings.iterator();
HandlerMapping hm = (HandlerMapping)var2.next();
handler = hm.getHandler(request);
} 03.我们转而去找HandlerMapping的getHandler()
却发现HandlerMapping是一个接口,所以我们就去找它的实现类AbstractHandlerMapping
-的getHandler() 如下:
public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception{
//将request转换成一个Handler
Object handler = this.getHandlerInternal(request);
return this.getHandlerExecutionChain(handler, request);
} 04. protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
HandlerExecutionChain chain = handler instanceof HandlerExecutionChain ? (HandlerExecutionChain)handler : new HandlerExecutionChain(handler);
String lookupPath = this.urlPathHelper.getLookupPathForRequest(request);
Iterator var5 = this.adaptedInterceptors.iterator(); while(var5.hasNext()) {
HandlerInterceptor interceptor = (HandlerInterceptor)var5.next();
if (interceptor instanceof MappedInterceptor) {
MappedInterceptor mappedInterceptor = (MappedInterceptor)interceptor;
if (mappedInterceptor.matches(lookupPath, this.pathMatcher)) {
chain.addInterceptor(mappedInterceptor.getInterceptor());
}
} else {
chain.addInterceptor(interceptor);
}
} return chain;
} 结论:处理器执行链=1个Handler+N个Interceptor
最新文章
- 查看mysql语句运行时间的2种方法
- TCP状态
- jquery颜色选择器
- EditText 显示明文和密码
- SQL SERVER 将表中字符串转换为数字的函数 (详询请加qq:2085920154)
- web中的触摸(touch)与手势(gesture)事件
- SourceTree 免登录跳过初始设置
- 修改linux系统时间的方法(date命令)
- CF 337D Book of Evil 树形DP 好题
- C#测量程序运行时间及cpu使用时间
- POJ 2431 Expedition (STL 优先权队列)
- java IO和NIO的场景选择
- scaletype
- 倒计时IE6+
- json转义字符串
- java线程与进程
- 【玩转开源】使用 PhoenixSuit 线刷 Android 镜像
- error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2
- python的for循环、while循环
- @Autowired Map<;String , Object>; xx