searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

spring mvc处理PathVariable源码解析

2024-04-26 01:07:27
0
0

如何处理将请求的赋值到control的参数中

  1. 解析出url对应的匹配规则,匹配到对应的参数,将解析出url对应的值放入
  2. 解析获得参数值,之后通过反射注入对应的方法中

1. 解析出url对应的匹配规则,匹配到对应的参数。

将解析出url对应的值放入request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, decodedUriVariables);


org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping 
protected void handleMatch

		Set<String> patterns = info.getPatternsCondition().getPatterns();
		if (patterns.isEmpty()) {
			bestPattern = lookupPath;
			uriVariables = Collections.emptyMap();
			decodedUriVariables = Collections.emptyMap();
		}
		else {
			bestPattern = patterns.iterator().next();
			uriVariables = getPathMatcher().extractUriTemplateVariables(bestPattern, lookupPath);
			decodedUriVariables = getUrlPathHelper().decodePathVariables(request, uriVariables);
		}

		request.setAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE, bestPattern);
		request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, decodedUriVariables);

 

matchStrings:692, AntPathMatcher$AntPathStringMatcher (org.springframework.util)
matchStrings:414, AntPathMatcher (org.springframework.util)
doMatch:213, AntPathMatcher (org.springframework.util)
extractUriTemplateVariables:491, AntPathMatcher (org.springframework.util)
handleMatch:131, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
handleMatch:57, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
lookupHandlerMethod:370, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:314, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:61, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandler:352, AbstractHandlerMapping (org.springframework.web.servlet.handler)
getHandler:1160, DispatcherServlet (org.springframework.web.servlet)
doDispatch:940, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doGet:861, FrameworkServlet (org.springframework.web.servlet)
service:635, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:359, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:728, ApplicationDispatcher (org.apache.catalina.core)
processRequest:470, ApplicationDispatcher (org.apache.catalina.core)
doForward:395, ApplicationDispatcher (org.apache.catalina.core)
forward:316, ApplicationDispatcher (org.apache.catalina.core)
doRestV2Filter:309, DomainFilter (com.chinanetcenter.wcs.interceptor)
doFilter:121, DomainFilter (com.chinanetcenter.wcs.interceptor)

堆栈:

handleMatch:136, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
handleMatch:57, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
lookupHandlerMethod:370, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:314, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:61, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandler:352, AbstractHandlerMapping (org.springframework.web.servlet.handler)
getHandler:1160, DispatcherServlet (org.springframework.web.servlet)
doDispatch:940, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doGet:861, FrameworkServlet (org.springframework.web.servlet)
service:635, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:359, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:728, ApplicationDispatcher (org.apache.catalina.core)
processRequest:470, ApplicationDispatcher (org.apache.catalina.core)
doForward:395, ApplicationDispatcher (org.apache.catalina.core)
forward:316, ApplicationDispatcher (org.apache.catalina.core)
doRestV2Filter:309, DomainFilter (com.chinanetcenter.wcs.interceptor)
doFilter:121, DomainFilter (com.chinanetcenter.wcs.interceptor)




2.解析获得参数值,之后通过反射注入对应的方法中。

 

堆栈

org.springframework.web.method.support.HandlerMethodArgumentResolverComposite
public Object resolveArgument



invoke:498, Method (java.lang.reflect)
doInvoke:205, InvocableHandlerMethod (org.springframework.web.method.support)
invokeForRequest:133, InvocableHandlerMethod (org.springframework.web.method.support)
invokeAndHandle:97, ServletInvocableHandlerMethod (org.springframework.web.servlet.mvc.method.annotation)
invokeHandlerMethod:827, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handleInternal:738, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handle:85, AbstractHandlerMethodAdapter (org.springframework.web.servlet.mvc.method)
doDispatch:967, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doGet:861, FrameworkServlet (org.springframework.web.servlet)
service:635, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:359, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:728, ApplicationDispatcher (org.apache.catalina.core)
processRequest:470, ApplicationDispatcher (org.apache.catalina.core)
doForward:395, ApplicationDispatcher (org.apache.catalina.core)
forward:316, ApplicationDispatcher (org.apache.catalina.core)
doRestV2Filter:309, DomainFilter (com.chinanetcenter.wcs.interceptor)

 

0条评论
0 / 1000
林维镇
5文章数
0粉丝数
林维镇
5 文章 | 0 粉丝
原创

spring mvc处理PathVariable源码解析

2024-04-26 01:07:27
0
0

如何处理将请求的赋值到control的参数中

  1. 解析出url对应的匹配规则,匹配到对应的参数,将解析出url对应的值放入
  2. 解析获得参数值,之后通过反射注入对应的方法中

1. 解析出url对应的匹配规则,匹配到对应的参数。

将解析出url对应的值放入request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, decodedUriVariables);


org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping 
protected void handleMatch

		Set<String> patterns = info.getPatternsCondition().getPatterns();
		if (patterns.isEmpty()) {
			bestPattern = lookupPath;
			uriVariables = Collections.emptyMap();
			decodedUriVariables = Collections.emptyMap();
		}
		else {
			bestPattern = patterns.iterator().next();
			uriVariables = getPathMatcher().extractUriTemplateVariables(bestPattern, lookupPath);
			decodedUriVariables = getUrlPathHelper().decodePathVariables(request, uriVariables);
		}

		request.setAttribute(BEST_MATCHING_PATTERN_ATTRIBUTE, bestPattern);
		request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, decodedUriVariables);

 

matchStrings:692, AntPathMatcher$AntPathStringMatcher (org.springframework.util)
matchStrings:414, AntPathMatcher (org.springframework.util)
doMatch:213, AntPathMatcher (org.springframework.util)
extractUriTemplateVariables:491, AntPathMatcher (org.springframework.util)
handleMatch:131, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
handleMatch:57, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
lookupHandlerMethod:370, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:314, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:61, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandler:352, AbstractHandlerMapping (org.springframework.web.servlet.handler)
getHandler:1160, DispatcherServlet (org.springframework.web.servlet)
doDispatch:940, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doGet:861, FrameworkServlet (org.springframework.web.servlet)
service:635, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:359, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:728, ApplicationDispatcher (org.apache.catalina.core)
processRequest:470, ApplicationDispatcher (org.apache.catalina.core)
doForward:395, ApplicationDispatcher (org.apache.catalina.core)
forward:316, ApplicationDispatcher (org.apache.catalina.core)
doRestV2Filter:309, DomainFilter (com.chinanetcenter.wcs.interceptor)
doFilter:121, DomainFilter (com.chinanetcenter.wcs.interceptor)

堆栈:

handleMatch:136, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
handleMatch:57, RequestMappingInfoHandlerMapping (org.springframework.web.servlet.mvc.method)
lookupHandlerMethod:370, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:314, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandlerInternal:61, AbstractHandlerMethodMapping (org.springframework.web.servlet.handler)
getHandler:352, AbstractHandlerMapping (org.springframework.web.servlet.handler)
getHandler:1160, DispatcherServlet (org.springframework.web.servlet)
doDispatch:940, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doGet:861, FrameworkServlet (org.springframework.web.servlet)
service:635, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:359, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:728, ApplicationDispatcher (org.apache.catalina.core)
processRequest:470, ApplicationDispatcher (org.apache.catalina.core)
doForward:395, ApplicationDispatcher (org.apache.catalina.core)
forward:316, ApplicationDispatcher (org.apache.catalina.core)
doRestV2Filter:309, DomainFilter (com.chinanetcenter.wcs.interceptor)
doFilter:121, DomainFilter (com.chinanetcenter.wcs.interceptor)




2.解析获得参数值,之后通过反射注入对应的方法中。

 

堆栈

org.springframework.web.method.support.HandlerMethodArgumentResolverComposite
public Object resolveArgument



invoke:498, Method (java.lang.reflect)
doInvoke:205, InvocableHandlerMethod (org.springframework.web.method.support)
invokeForRequest:133, InvocableHandlerMethod (org.springframework.web.method.support)
invokeAndHandle:97, ServletInvocableHandlerMethod (org.springframework.web.servlet.mvc.method.annotation)
invokeHandlerMethod:827, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handleInternal:738, RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation)
handle:85, AbstractHandlerMethodAdapter (org.springframework.web.servlet.mvc.method)
doDispatch:967, DispatcherServlet (org.springframework.web.servlet)
doService:901, DispatcherServlet (org.springframework.web.servlet)
processRequest:970, FrameworkServlet (org.springframework.web.servlet)
doGet:861, FrameworkServlet (org.springframework.web.servlet)
service:635, HttpServlet (javax.servlet.http)
service:846, FrameworkServlet (org.springframework.web.servlet)
service:742, HttpServlet (javax.servlet.http)
internalDoFilter:231, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:52, WsFilter (org.apache.tomcat.websocket.server)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
doFilter:359, VosDspLogFilter (com.chinanetcenter.wcs.servlet)
internalDoFilter:193, ApplicationFilterChain (org.apache.catalina.core)
doFilter:166, ApplicationFilterChain (org.apache.catalina.core)
invoke:728, ApplicationDispatcher (org.apache.catalina.core)
processRequest:470, ApplicationDispatcher (org.apache.catalina.core)
doForward:395, ApplicationDispatcher (org.apache.catalina.core)
forward:316, ApplicationDispatcher (org.apache.catalina.core)
doRestV2Filter:309, DomainFilter (com.chinanetcenter.wcs.interceptor)

 

文章来自个人专栏
性能调优
5 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0