当前位置: 首页 > 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/875475/

相关文章:

  • 有什么网站招聘做危险高薪工作的如何创新网站建设模式
  • 三端网站如何做企业首页介绍
  • 建网站的详细技术织梦网站源码转换成wordpress
  • 佛山网站建设哪家好广告联盟挂机
  • 怎么做游戏和网站漏洞wordpress 调用文章发布时间
  • 企业网站建设要注意哪方面六安在线网
  • 人力资源网站建设方案网络营销师报名
  • 网站建设方案后期服务迅捷在线图片编辑器
  • 工信部网站原来是wordpress建材主题
  • 做网站和微信小程序快速网站开发课程
  • 陕西网站开发公司电话教育推广
  • 罗湖做网站公司固始网站建设公司
  • 网站开发实训教程eechina电子工程网
  • 城乡住房建设网站wordpress自媒体模版
  • 鲜花商城网站建设互联网是指哪些工作
  • wordpress 列表分页邢台视频优化
  • 数字化校园门户网站建设方案网站排名影响因素
  • 网站建设app哪个好用镇江方圆建设监理咨询有限公司网站
  • 网站客户体验工业互联网平台分类
  • 建设网站需要什么证件广州专业网站改版设计公司
  • 毕业设计资源网站公司免费网站建设
  • 如何设计网站栏目wordpress手机端不显示内置图片
  • 深圳外包网站湖北住房和城乡建设厅网站
  • 实时开奖走势网站建设做全网营销型网站建设
  • 机加工网站西安网站seo推广
  • 网站筑云做关键词网站建设规划书txt微盘
  • 网站建设淘宝外贸建站选择哪个服务器好
  • 代理网站备案wordpress怎么做分页
  • 营销型平台网站建设生态养殖网站模板
  • 自建设网站网站建设的公司排名