- 前言
- 第一部分 核心实现
- 第 1 章 Spring 整体架构和环境搭建
- 第 2 章 容器的基本实现
- 第 3 章 默认标签的解析
- 第 4 章 自定义标签的解析
- 第 5 章 bean 的加载
- 第 6 章 容器的功能扩展
- 第 7 章 AOP
- 第二部分 企业应用
- 第 8 章 数据库连接 JDBC
- 第 9 章 整合 MyBatis
- 第 10 章 事务
- 第 11 章 SpringMVC
- 第 12 章 远程服务
- 第 13 章 Spring 消息
11.4.7 逻辑处理
对于逻辑处理其实是通过适配器中转调用 Handler 并返回视图的,对应代码:
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
同样,还是以引导示例为基础进行处理逻辑分析,之前分析过,对于普通的 Web 请求,Spring 默认使用 SimpleControllerHandlerAdapter 类进行处理,我们进入 SimpleControllerHandlerAdapter 类的 handle 方法如下:
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response,
Object handler)
throws Exception {
return ((Controller) handler).handleRequest(request, response);
}
但是回顾引导示例中的 UserController,我们的逻辑是写在 handleRequestInternal 函数中而不是 handleRequest 函数,所以我们还需要进一步分析这期间所包含的处理流程。
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Delegate to WebContentGenerator for checking and preparing.
checkAndPrepare(request, response, this instanceof LastModified);
//如果需要 session 内的同步执行
if (this.synchronizeOnSession) {
HttpSession session = request.getSession(false);
if (session != null) {
Object mutex = WebUtils.getSessionMutex(session);
synchronized (mutex) {
//调用用户的逻辑
return handleRequestInternal(request, response);
}
}
}
//调用用户逻辑
return handleRequestInternal(request, response);
}
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论