局机关建设网站的意义,怎么做企业网站平台,网站打不开dns修改,常州做的网站的公司网站说明
本文基于 jdk 8, spring-framework 5.2.x 编写。author JellyfishMIX - github / blog.jellyfishmix.comLICENSE GPL-2.0
类层次 HandlerMethod#xff0c;处理器的方法的封装对象。HandlerMethod 只提供了处理器的方法的基本信息#xff0c;不提供调用逻辑。
Invoca…说明
本文基于 jdk 8, spring-framework 5.2.x 编写。author JellyfishMIX - github / blog.jellyfishmix.comLICENSE GPL-2.0
类层次 HandlerMethod处理器的方法的封装对象。HandlerMethod 只提供了处理器的方法的基本信息不提供调用逻辑。
InvocableHandlerMethod继承 HandlerMethod 类可调用的 HandlerMethod 实现类。
ServletInvocableHandlerMethod#invokeAndHandle 方法
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod#invokeAndHandle
核心方法处理请求。
执行调用处理请求设置 responseStatus。如果 returnValue 为空设置 ModelAndViewContainer 为请求已处理然后 return和 ResponseStatus 注解相关。设置 ModelAndViewContainer 为请求未处理通过 HandlerMethodReturnValueHandlerComposite(HandlerMethodReturnValueHandler) 处理返回值。
public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {Nullableprivate HandlerMethodReturnValueHandlerComposite returnValueHandlers;public void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer mavContainer,Object... providedArgs) throws Exception {// 执行调用处理请求Object returnValue invokeForRequest(webRequest, mavContainer, providedArgs);// 设置 responseStatussetResponseStatus(webRequest);// 如果 returnValue 为空设置 ModelAndViewContainer 为请求已处理然后 return和 ResponseStatus 注解相关if (returnValue null) {if (isRequestNotModified(webRequest) || getResponseStatus() ! null || mavContainer.isRequestHandled()) {disableContentCachingIfNecessary(webRequest);mavContainer.setRequestHandled(true);return;}}else if (StringUtils.hasText(getResponseStatusReason())) {mavContainer.setRequestHandled(true);return;}// 设置 ModelAndViewContainer 为请求未处理mavContainer.setRequestHandled(false);Assert.state(this.returnValueHandlers ! null, No return value handlers);try {// 通过 HandlerMethodReturnValueHandlerComposite(HandlerMethodReturnValueHandler) 处理返回值this.returnValueHandlers.handleReturnValue(returnValue, getReturnValueType(returnValue), mavContainer, webRequest);}catch (Exception ex) {if (logger.isTraceEnabled()) {logger.trace(formatErrorForReturnValue(returnValue), ex);}throw ex;}}
}ServletInvocableHandlerMethod#setResponseStatus 方法
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod#setResponseStatus
调用 setResponseStatus(ServletWebRequest webRequest) 设置响应的状态码。
获得 status和 ResponseStatus 注解相关。设置响应的状态码。有 reason则设置 status reason。无 reason仅设置 status。RedirectView 相关。 private void setResponseStatus(ServletWebRequest webRequest) throws IOException {// 获得 status和 ResponseStatus 注解相关HttpStatus status getResponseStatus();if (status null) {return;}// 设置响应的状态码HttpServletResponse response webRequest.getResponse();if (response ! null) {String reason getResponseStatusReason();// 有 reason则设置 status reasonif (StringUtils.hasText(reason)) {response.sendError(status.value(), reason);}else {// 无 reason仅设置 statusresponse.setStatus(status.value());}}// To be picked up by RedirectView// RedirectView 相关webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, status);}InvocableHandlerMethod
InvocableHandlerMethod#invokeForRequest 方法 – 执行调用处理请求
org.springframework.web.method.support.InvocableHandlerMethod#invokeForRequest
执行调用处理请求。 Nullablepublic Object invokeForRequest(NativeWebRequest request, Nullable ModelAndViewContainer mavContainer,Object... providedArgs) throws Exception {// 解析参数Object[] args getMethodArgumentValues(request, mavContainer, providedArgs);if (logger.isTraceEnabled()) {logger.trace(Arguments: Arrays.toString(args));}// 执行调用return doInvoke(args);}InvocableHandlerMethod#getMethodArgumentValues 方法 – 解析参数
org.springframework.web.method.support.InvocableHandlerMethod#getMethodArgumentValues
获得方法的参数。遍历方法参数将参数解析成对应的类型。 获得当前遍历的 MethodParameter 对象给它设置 parameterNameDiscoverer。从 providedArgs 中获得参数。如果获得到则进入下一个参数的解析默认情况 providedArgs 不会传参。判断 resolvers 是否支持当前的参数解析。执行参数解析解析成功后进入下一个参数的解析。
protected Object[] getMethodArgumentValues(NativeWebRequest request, Nullable ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception {// 获得方法的参数MethodParameter[] parameters getMethodParameters();// 无参返回空数组if (ObjectUtils.isEmpty(parameters)) {return EMPTY_ARGS;}// 遍历方法参数将参数解析成对应的类型Object[] args new Object[parameters.length];for (int i 0; i parameters.length; i) {// 获得当前遍历的 MethodParameter 对象给它设置 parameterNameDiscovererMethodParameter parameter parameters[i];parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);// 从 providedArgs 中获得参数。如果获得到则进入下一个参数的解析默认情况 providedArgs 不会传参。args[i] findProvidedArgument(parameter, providedArgs);if (args[i] ! null) {continue;}// 判断 resolvers 是否支持当前的参数解析if (!this.resolvers.supportsParameter(parameter)) {throw new IllegalStateException(formatArgumentError(parameter, No suitable resolver));}try {// 执行参数解析解析成功后进入下一个参数的解析args[i] this.resolvers.resolveArgument(parameter, mavContainer, request, this.dataBinderFactory);}catch (Exception ex) {// Leave stack trace for later, exception may actually be resolved and handled...if (logger.isDebugEnabled()) {String exMsg ex.getMessage();if (exMsg ! null !exMsg.contains(parameter.getExecutable().toGenericString())) {logger.debug(formatArgumentError(parameter, exMsg));}}throw ex;}}return args;}InvocableHandlerMethod#doInvoke 方法
org.springframework.web.method.support.InvocableHandlerMethod#doInvoke
设置方法为可访问。通过反射执行方法调用。BridgedMethod 基于泛型安全为了和 jdk 1.5 之前的字节码兼容无需关注 BridgedMethod。 Nullableprotected Object doInvoke(Object... args) throws Exception {// 设置方法为可访问ReflectionUtils.makeAccessible(getBridgedMethod());try {// 通过反射执行方法调用。BridgedMethod 基于泛型安全为了和 jdk 1.5 之前的字节码兼容无需关注 BridgedMethodreturn getBridgedMethod().invoke(getBean(), args);}catch (IllegalArgumentException ex) {assertTargetBean(getBridgedMethod(), getBean(), args);String text (ex.getMessage() ! null ? ex.getMessage() : Illegal argument);throw new IllegalStateException(formatInvokeError(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 {throw new IllegalStateException(formatInvokeError(Invocation failure, args), targetException);}}}后言
本文可以看到很重要的两个组件 HandlerMethodArgumentResolver 用于获取请求参数HandlerMethodReturnValueHandler 用于处理返回值后续分析。 文章转载自: http://www.morning.znlhc.cn.gov.cn.znlhc.cn http://www.morning.tntqr.cn.gov.cn.tntqr.cn http://www.morning.dfhkh.cn.gov.cn.dfhkh.cn http://www.morning.rdsst.cn.gov.cn.rdsst.cn http://www.morning.bpmtl.cn.gov.cn.bpmtl.cn http://www.morning.nbdtdjk.cn.gov.cn.nbdtdjk.cn http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn http://www.morning.wbqk.cn.gov.cn.wbqk.cn http://www.morning.brzlp.cn.gov.cn.brzlp.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.lkwyr.cn.gov.cn.lkwyr.cn http://www.morning.bnxnq.cn.gov.cn.bnxnq.cn http://www.morning.dfdhx.cn.gov.cn.dfdhx.cn http://www.morning.qtkfp.cn.gov.cn.qtkfp.cn http://www.morning.ryrpq.cn.gov.cn.ryrpq.cn http://www.morning.kpbq.cn.gov.cn.kpbq.cn http://www.morning.wpqwk.cn.gov.cn.wpqwk.cn http://www.morning.jcxqc.cn.gov.cn.jcxqc.cn http://www.morning.jypsm.cn.gov.cn.jypsm.cn http://www.morning.nmtyx.cn.gov.cn.nmtyx.cn http://www.morning.fcqlt.cn.gov.cn.fcqlt.cn http://www.morning.lqffg.cn.gov.cn.lqffg.cn http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn http://www.morning.pjtw.cn.gov.cn.pjtw.cn http://www.morning.dtmjn.cn.gov.cn.dtmjn.cn http://www.morning.wjhnx.cn.gov.cn.wjhnx.cn http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn http://www.morning.fdmfn.cn.gov.cn.fdmfn.cn http://www.morning.lxthr.cn.gov.cn.lxthr.cn http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.rknhd.cn.gov.cn.rknhd.cn http://www.morning.mqbzk.cn.gov.cn.mqbzk.cn http://www.morning.tjpmf.cn.gov.cn.tjpmf.cn http://www.morning.txlnd.cn.gov.cn.txlnd.cn http://www.morning.xgmf.cn.gov.cn.xgmf.cn http://www.morning.tjjkn.cn.gov.cn.tjjkn.cn http://www.morning.rwwdp.cn.gov.cn.rwwdp.cn http://www.morning.kvzvoew.cn.gov.cn.kvzvoew.cn http://www.morning.wpjst.cn.gov.cn.wpjst.cn http://www.morning.yptwn.cn.gov.cn.yptwn.cn http://www.morning.nknt.cn.gov.cn.nknt.cn http://www.morning.wgzgr.cn.gov.cn.wgzgr.cn http://www.morning.fbxlj.cn.gov.cn.fbxlj.cn http://www.morning.xnwjt.cn.gov.cn.xnwjt.cn http://www.morning.yhtnr.cn.gov.cn.yhtnr.cn http://www.morning.fhykt.cn.gov.cn.fhykt.cn http://www.morning.c7622.cn.gov.cn.c7622.cn http://www.morning.mrnnb.cn.gov.cn.mrnnb.cn http://www.morning.jspnx.cn.gov.cn.jspnx.cn http://www.morning.bmmhs.cn.gov.cn.bmmhs.cn http://www.morning.lmtbl.cn.gov.cn.lmtbl.cn http://www.morning.rqwmt.cn.gov.cn.rqwmt.cn http://www.morning.sqgqh.cn.gov.cn.sqgqh.cn http://www.morning.hkswt.cn.gov.cn.hkswt.cn http://www.morning.807yy.cn.gov.cn.807yy.cn http://www.morning.dtzsm.cn.gov.cn.dtzsm.cn http://www.morning.pfntr.cn.gov.cn.pfntr.cn http://www.morning.tsynj.cn.gov.cn.tsynj.cn http://www.morning.hlxpz.cn.gov.cn.hlxpz.cn http://www.morning.wmrgp.cn.gov.cn.wmrgp.cn http://www.morning.rnqnp.cn.gov.cn.rnqnp.cn http://www.morning.bpmfl.cn.gov.cn.bpmfl.cn http://www.morning.wrbnh.cn.gov.cn.wrbnh.cn http://www.morning.hxcrd.cn.gov.cn.hxcrd.cn http://www.morning.lbggk.cn.gov.cn.lbggk.cn http://www.morning.kgqpx.cn.gov.cn.kgqpx.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.mcpby.cn.gov.cn.mcpby.cn http://www.morning.hmxb.cn.gov.cn.hmxb.cn http://www.morning.rdnpg.cn.gov.cn.rdnpg.cn http://www.morning.bnlkc.cn.gov.cn.bnlkc.cn http://www.morning.jxltk.cn.gov.cn.jxltk.cn http://www.morning.pfnlc.cn.gov.cn.pfnlc.cn http://www.morning.hpspr.com.gov.cn.hpspr.com http://www.morning.nzmhk.cn.gov.cn.nzmhk.cn http://www.morning.wmgjq.cn.gov.cn.wmgjq.cn http://www.morning.ldgqh.cn.gov.cn.ldgqh.cn http://www.morning.clhyj.cn.gov.cn.clhyj.cn http://www.morning.jbtzx.cn.gov.cn.jbtzx.cn http://www.morning.jrplk.cn.gov.cn.jrplk.cn