当前位置: 首页 > news >正文

360建筑网如何删除简历济南网站优化

360建筑网如何删除简历,济南网站优化,网页模板下载工具,做seo排名好的网站1、启动初始化 核心:得到应用上下文中存在的全部bean后依次遍历,分析每一个目标handler & 目标方法存在的注解RequestMapping,将其相关属性封装为实例RequestMappingInfo。最终将 uri & handler 之间的映射关系维护在类AbstractHand…

1、启动初始化

核心:得到应用上下文中存在的全部bean后依次遍历,分析每一个目标handler & 目标方法存在的注解@RequestMapping,将其相关属性封装为实例RequestMappingInfo。最终将 uri & handler 之间的映射关系维护在类AbstractHandlerMethodMapping中的内部类RequestMappingInfo中。

利用RequestMappingHandlerMappingInitializingBean接口特性来完成请求 uri & handler 之间的映射关系。具体详情参考其父类AbstractHandlerMethodMapping实现其功能,如下:

public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMapping implements InitializingBean {//内部类private final MappingRegistry mappingRegistry = new MappingRegistry();protected void initHandlerMethods() {for (String beanName : getCandidateBeanNames()) {//从应用上下文中获取全部的beanprocessCandidateBean(beanName);}}protected void processCandidateBean(String beanName) {Class<?> beanType = obtainApplicationContext().getType(beanName);// 判断是否为Handler的条件为:是否存在注解Controller 或者 RequestMappingif (beanType != null && isHandler(beanType)) {detectHandlerMethods(beanName);}}protected void detectHandlerMethods(Object handler) {//handler为String类型的beanNameClass<?> handlerType = (handler instanceof String ?obtainApplicationContext().getType((String) handler) : handler.getClass());if (handlerType != null) {Class<?> userType = ClassUtils.getUserClass(handlerType);// 集合methods其key:反射中Method类。value:RequestMappingInfoMap<Method, T> methods = MethodIntrospector.selectMethods(userType,(MethodIntrospector.MetadataLookup<T>) method -> {// 调用具体的实现类,例如RequestMappingHandlerMappingreturn getMappingForMethod(method, userType);});methods.forEach((method, mapping) -> {Method invocableMethod = AopUtils.selectInvocableMethod(method, userType);registerHandlerMethod(handler, invocableMethod, mapping);});}}protected void registerHandlerMethod(Object handler, Method method, T mapping) {this.mappingRegistry.register(mapping, handler, method);}
}

1.1、RequestMappingHandlerMapping

解析目标类 & 目标方法之@RequestMapping注解相关属性。

public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping{@Override@Nullableprotected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {//将目标方法存在的@RequestMapping注解相关属性封装为RequestMappingInfoRequestMappingInfo info = createRequestMappingInfo(method);if (info != null) {//如果目标handler也存在@RequestMapping注解,则也封装为RequestMappingInfoRequestMappingInfo typeInfo = createRequestMappingInfo(handlerType);if (typeInfo != null) {// 将目标方法@RequestMapping相关属性与目标handler之@RequestMapping相关属性合并起来info = typeInfo.combine(info);}String prefix = getPathPrefix(handlerType);//获取目标handler之url前缀if (prefix != null) {info = RequestMappingInfo.paths(prefix).options(this.config).build().combine(info);}}return info;}private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);return (requestMapping != null ? createRequestMappingInfo(requestMapping, null) : null);}protected RequestMappingInfo createRequestMappingInfo(RequestMapping requestMapping,RequestCondition condition) {// 获取某个具体目标方法其@RequestMapping注解相关属性,最终封装为RequestMappingInfoRequestMappingInfo.Builder builder = RequestMappingInfo.paths(resolveEmbeddedValuesInPatterns(requestMapping.path())).methods(requestMapping.method()).params(requestMapping.params()).headers(requestMapping.headers()).consumes(requestMapping.consumes()).produces(requestMapping.produces()).mappingName(requestMapping.name());return builder.options(this.config).build();}
}

1.2.MappingRegistry

public abstract class AbstractHandlerMethodMapping<T> {class MappingRegistry {private final Map<T, MappingRegistration<T>> registry = new HashMap<>();//集合mappingLookup之key:RequestMappingInfo。value:HandlerMethodprivate final Map<T, HandlerMethod> mappingLookup = new LinkedHashMap<>();private final MultiValueMap<String, T> urlLookup = new LinkedMultiValueMap<>();public void register(T mapping, Object handler, Method method) {...// 目标类的目标方法最终封装为HandlerMethod  handler实为目标bean的beanNameHandlerMethod handlerMethod = createHandlerMethod(handler, method);this.mappingLookup.put(mapping, handlerMethod);List<String> directUrls = getDirectUrls(mapping);for (String url : directUrls) {this.urlLookup.add(url, mapping);}...this.registry.put(mapping, new MappingRegistration<>(mapping, handlerMethod, directUrls, name));}}
}

2、处理请求

SpringMVC利用请求url获取目标handler。
在这里插入图片描述

public class DispatcherServlet extends FrameworkServlet {@Nullableprotected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {if (this.handlerMappings != null) {for (HandlerMapping mapping : this.handlerMappings) {// 围绕 RequestMappingHandlerMapping 展开HandlerExecutionChain handler = mapping.getHandler(request);if (handler != null) {return handler;}}}return null;}
}
public abstract class AbstractHandlerMethodMapping<T>  implements InitializingBean {private final MappingRegistry mappingRegistry = new MappingRegistry();@Overrideprotected HandlerMethod getHandlerInternal(HttpServletRequest request){// 获取requestUriString lookupPath = getUrlPathHelper().getLookupPathForRequest(request);// 从 mappingRegistry 获取目标handlerHandlerMethod handlerMethod = lookupHandlerMethod(lookupPath, request);return (handlerMethod != null ? handlerMethod.createWithResolvedBean() : null);}protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) {List<Match> matches = new ArrayList<>();// 利用 lookupPath 从MappingRegistry相关属性中获取目标handler之TList<T> directPathMatches = this.mappingRegistry.getMappingsByUrl(lookupPath);// 通过章节1得知,返回的类为 RequestMappingInfo,即@RequestMapping注解的相关属性if (directPathMatches != null) {//分析请求addMatchingMappings(directPathMatches, matches, request);}if (matches.isEmpty()) {// No choice but to go through all mappings...addMatchingMappings(this.mappingRegistry.getMappings().keySet(), matches, request);}// 如果局部matches中元素为空,说明请求头校验失败if (!matches.isEmpty()) {Comparator<Match> comparator = new MatchComparator(getMappingComparator(request));matches.sort(comparator);Match bestMatch = matches.get(0);...request.setAttribute(BEST_MATCHING_HANDLER_ATTRIBUTE, bestMatch.handlerMethod);handleMatch(bestMatch.mapping, lookupPath, request);return bestMatch.handlerMethod;}else {//最终此处抛出相关的异常return handleNoMatch(this.mappingRegistry.getMappings().keySet(), lookupPath, request);}}
}

请求头相关参数校验失败抛出的异常包括:HttpRequestMethodNotSupportedExceptionHttpMediaTypeNotSupportedExceptionHttpMediaTypeNotAcceptableExceptionUnsatisfiedServletRequestParameterException

但是这些类型的异常好像不能被全局拦截器拦截处理。

2.1.解析请求头相关属性

核心就是校验请求request中相关属性跟RequestMappingInfo中属性是否匹配。

public abstract class AbstractHandlerMethodMapping<T>  implements InitializingBean {private void addMatchingMappings(Collection mappings, List matches, HttpServletRequest request) {for (T mapping : mappings) {T match = getMatchingMapping(mapping, request);if (match != null) {//正常请求校验都通过,最终返回重新包装后的RequestMappingInfomatches.add(new Match(match, this.mappingRegistry.getMappings().get(mapping)));}}}
}
public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMethodMapping {@Overrideprotected RequestMappingInfo getMatchingMapping(RequestMappingInfo info, HttpServletRequest request) {return info.getMatchingCondition(request);}
}

2.1.1、RequestMappingInfo

该类中的相关属性是对 注解@RequestMapping之字段属性的封装。

public final class RequestMappingInfo implements RequestCondition<RequestMappingInfo> {public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {//请求方式: 校验Method属性,即是否为post or get 等相对应的请求方式RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);if (methods == null) {return null;}//请求参数ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);if (params == null) {return null;}//consumer参数:请求头中contentType是否一致。HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);if (headers == null) {return null;}//producer参数:请求头中Accept是否一致ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);if (consumes == null) {return null;}ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);if (produces == null) {return null;}PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);if (patterns == null) {return null;}RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request);if (custom == null) {return null;}return new RequestMappingInfo(this.name, patterns,methods, params, headers, consumes, produces, custom.getCondition());}
}
http://www.shuangfujiaoyu.com/news/52160.html

相关文章:

  • 可以做推广的网站有哪些seo人人网
  • 找公司做网站要注意什么问题数据分析
  • 网络营销网站开发广州搜索seo网站优化
  • 蓝色门户网站湖南 seo
  • 如何抄袭网站seo搜索引擎的优化
  • html和css制作简单网页代码合肥网站优化公司
  • 免费教做面食的网站现在怎么做网络推广
  • 网站建设com网站服务器
  • 如何做楼盘网站网站推广交换链接
  • 网站忧化技巧百度怎么推广产品
  • 网站怎么做二维码链接地址网站seo诊断优化方案
  • 网站的制作建站人广告传媒公司
  • 兄弟们来个能看的潮州seo
  • 单位网站查询工资链接怎么做临沂做网络优化的公司
  • 垂直网站做排名想学编程去哪里找培训班
  • 北洼路网站建设最好的推广平台排名
  • 媒体平台推广百度seo关键词优化推荐
  • asp做网站计数器百度的营销策略
  • 做网站的标准seo服务 文库
  • 网站自己服务器互动营销是什么意思
  • ps做图下载网站竞价推广是什么工作
  • 企业建网站有这个必要吗如何做好一个品牌推广
  • 跳转网站怎么做写软文怎么接单子
  • 济南网站开发建设小广告模板
  • 杭州 网站定制德阳网站seo
  • 乡镇政府关于加强政务网站建设阳城seo排名
  • 杭州网站建设制作公司网络营销什么意思
  • 河南网站建设设计免费crm系统手机版
  • 个人模板网站下载百度
  • 触屏网站开发教程谷歌关键词查询工具