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

家用机能否做网站服务器昆山营销型网站建设方法

家用机能否做网站服务器,昆山营销型网站建设方法,凡科做的微网站怎样连接公众号,布谷 海南网站建设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.yayakq.cn/news/511049/

相关文章:

  • 岳阳网站开发公司网站开发用什么框架好
  • 国外优秀的网站设计在线网页视频提取
  • 网站建设佰首选金手指二宁波品牌设计
  • 合肥网站建设平台网站规划的类型
  • 做专利费减是哪个网站更新不了wordpress
  • 网站建设是干什么建网站做cpa
  • 网站关键字如何设置建设网站协议
  • 网站开发服务器多少钱wordpress缩略图只生成full
  • 坦桑尼亚网站域名后缀个人中心网页
  • 网站建设 个体经营范围泉州企业免费建站
  • 美的集团网站建设网站建设开发报价方案模板
  • 如何做好网站建设前期网站规划工商注册网站
  • 鞍山做网站排名手机网站源程序
  • 安康网站开发公司价格去除页面标题的wordpress
  • 网站开发技术主题卫星宽带app
  • 中企动力网站推广php网站开发套模板步骤
  • 推荐做网站的话术郑州知名网站建设
  • 公司网站地图怎么做公关公司排名2020
  • 建网站郑州个人网站界面设计图片
  • 服装企业的网站建设池州城乡住房建设厅网站
  • 线上做交互的网站网站建设实训报告收获
  • 住房和城乡建设部网站职称查询wordpress电影站主题
  • 专门做防盗门的网站湖北立方建设工程有限公司网站
  • 营销导向企业网站建设百度网站大全
  • 图书馆门户网站建设的意义阿里云成功备案的网站增加域名
  • 做网站 前途网站空间 数据库
  • 填空秒懂网站西安跨境电子商务平台网站
  • 帝国cms网站源码邵阳建设银行网站是多少
  • 用asp做旅游网站厦门网站网页设
  • 杭州网站建设公司中国建设传媒网官网