实现思路

请求路径如:/person/list/101。使用正则将id为key,101为value填充到map中放到request域中。为目标方法形参设置参数时拿出request域中的值然后赋值。

实现原理

@PathVariable注解对应的解析器是PathVariableMethodArgumentResolver

根据HandlerMapping映射处理器获得HandlerExecutionChain

mappedHandler = getHandler(processedRequest);

获得请求的目标方法的包装类HandlerMethod

Object handler = getHandlerInternal(request);

查找与请求路径正则匹配的目标方法

HandlerMethod handlerMethod = lookupHandlerMethod(lookupPath, request);
List<Match> matches = new ArrayList<Match>();
// 获得匹配的映射Match(RequestMappingInfo, HandlerMethod) addMatchingMappings(
this.mappingRegistry.getMappings().keySet(), matches, request);
// 处理匹配成功的映射 handleMatch(bestMatch.mapping, lookupPath, request);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-06-30
  • 2021-08-02
猜你喜欢
  • 2021-10-19
  • 2022-12-23
  • 2021-09-05
  • 2021-07-21
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案