SpringMVC源码解析之ServletInvocableHandlerMethod
发布日期:2021-06-30 12:25:41
浏览次数:2
分类:技术文章
本文共 2720 字,大约阅读时间需要 9 分钟。
InvocableHandlerMethod
提供了一种方法,用于调用处理器方法,处理给定的请求,其已通过注册的HandlerMethodArgumentResolver解析了方法参数值。
参数解析往往需要WebDataBinder用于数据结合或进行类型转换。 使用setDataBinderFactory(WebDataBinderFactory)属性来提供一种粘合剂厂传递给参数解析器。
使用setHandlerMethodArgumentResolvers自定义的参数解析器的列表。invokeForRequest
解析给定请求的上下文中其参数值后调用指定方法。
参数值是通过HandlerMethodArgumentResolver解析的。doInvoke
调用与给定的参数值的处理方法
protected Object doInvoke(Object... args) throws Exception { ReflectionUtils.makeAccessible(getBridgedMethod()); try { return getBridgedMethod().invoke(getBean(), args); } catch (IllegalArgumentException ex) { assertTargetBean(getBridgedMethod(), getBean(), args); String text = (ex.getMessage() != null ? ex.getMessage() : "Illegal argument"); throw new IllegalStateException(getInvocationErrorMessage(text, args), ex); } catch (InvocationTargetException ex) { // Unwrap for HandlerExceptionResolvers ... Throwable targetException = ex.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } else if (targetException instanceof Error) { throw (Error) targetException; } else if (targetException instanceof Exception) { throw (Exception) targetException; } else { String text = getInvocationErrorMessage("Failed to invoke handler method", args); throw new IllegalStateException(text, targetException); } } }
ServletInvocableHandlerMethod
扩展InvocableHandlerMethod通过注册的能力来处理返回值HandlerMethodReturnValueHandler并且还支持设置基于方法级响应状态@ResponseStatus注解。
甲null返回值(包括空隙)可以被解释为请求处理结束结合有@ResponseStatus注释,未改性的检查条件(见ServletWebRequest.checkNotModified(long) ),或提供对所述接入的方法的参数响应流invokeAndHandle
调用该方法,并通过所配置的HandlerMethodReturnValueHandler处理返回值
- WebRequest - 当前请求
- mavContainer - 在ModelAndViewContainer此请求
- providedArgs - “给”论据类型匹配(未解析)
public void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception { Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs); setResponseStatus(webRequest); if (returnValue == null) { if (isRequestNotModified(webRequest) || getResponseStatus() != null || mavContainer.isRequestHandled()) { mavContainer.setRequestHandled(true); return; } } else if (StringUtils.hasText(getResponseStatusReason())) { mavContainer.setRequestHandled(true); return; } mavContainer.setRequestHandled(false); try { this.returnValueHandlers.handleReturnValue( returnValue, getReturnValueType(returnValue), mavContainer, webRequest); } catch (Exception ex) { if (logger.isTraceEnabled()) { logger.trace(getReturnValueHandlingErrorMessage("Error handling return value", returnValue), ex); } throw ex; }}
转载地址:https://javaedge.blog.csdn.net/article/details/106551309 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
很好
[***.229.124.182]2024年04月12日 01时38分27秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Shell case语句
2019-04-30
Shell添加指定数量的用户
2019-04-30
Oracle行转列的一次经历
2019-04-30
linux安装node环境
2019-04-30
搭建Weex开发环境,以及遇到的一些坑
2019-04-30
Weex helloworld入门
2019-04-30
python面向对象(一)
2019-04-30
python中web.py框架的搭建
2019-04-30
python后台框架web.py使用render模板
2019-04-30
No module named MYSQLdb 问题解决
2019-04-30
python文件打开方式
2019-04-30
python汉子转码
2019-04-30
IDEA文件目录介绍
2019-04-30
IDEA2018注册码
2019-04-30
记事本的三个技巧
2019-04-30
IDEA debug操作
2019-04-30
Dojo开发(一)
2019-04-30
Excel将一列数据分隔成多列
2019-04-30