上篇文章里,我们讲解了RequestMappingHandlerMapping请求地址映射的初始化流程,理解了@Controller@RequestMapping是如何被加载到缓存中的。

今天我们来进一步学习,在接收到请求时,RequestMappingHandlerMapping是如何进行请求地址映射的。

先放一个类图,在请求地址映射过程中,会依次执行到这些方法:

1 HandlerMapping

首先,DispatcherServlet会调用HandlerMapping接口的getHandler()方法:

HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception;

这个方法主要起着规范的作用,DispatcherServlet可以根据这个方法调用所有HandlerMapping实现类进行请求地址映射。

2 AbstractHandlerMapping

AbstractHandlerMapping是所有HandlerMapping的抽象基类,提供了拦截器、排序和默认处理器等功能。

AbstractHandlerMapping是常见HandlerMapping实现类的共同父类,它的核心功能是定义了获取HandlerExecutionChain的基础流程:

  1. 获取handler(由实现类定义具体逻辑)
  2. 创建HandlerExecutionChain,添加拦截器
  3. 添加跨域拦截器

AbstractHandlerMappinggetHandler()源码如下:

public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
// 1、获取handler
Object handler = getHandlerInternal(request);
if (handler == null) {
handler = getDefaultHandler();
}
if (handler == null) {
return null;
}
// Bean name or resolved handler?
if (handler instanceof String) {
String handlerName = (String) handler;
handler = obtainApplicationContext().getBean(handlerName);
} // Ensure presence of cached lookupPath for interceptors and others
if (!ServletRequestPathUtils.hasCachedPath(request)) {
initLookupPath(request);
}
// 2、创建HandlerExecutionChain,添加拦截器
HandlerExecutionChain executionChain = getHandlerExecutionChain(handler, request); if (logger.isTraceEnabled()) {
logger.trace("Mapped to " + handler);
}
else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDispatcherType())) {
logger.debug("Mapped to " + executionChain.getHandler());
}
// 3、添加跨域拦截器
if (hasCorsConfigurationSource(handler) || CorsUtils.isPreFlightRequest(request)) {
CorsConfiguration config = getCorsConfiguration(handler, request);
if (getCorsConfigurationSource() != null) {
CorsConfiguration globalConfig = getCorsConfigurationSource().getCorsConfiguration(request);
config = (globalConfig != null ? globalConfig.combine(config) : config);
}
if (config != null) {
config.validateAllowCredentials();
}
executionChain = getCorsHandlerExecutionChain(request, executionChain, config);
} return executionChain;
}

2.1 获取handler

AbstractHandlerMapping通过getHandlerInternal()方法获取handler

该方法由具体实现类进行实现,如果找到匹配的handler,则会返回该handler;如果没有找到,则会返回null

具体实现我们会在下文的实现类中进行讲解。

2.2 创建HandlerExecutionChain,添加拦截器

AbstractHandlerMapping通过getHandlerExecutionChain()方法创建HandlerExecutionChain对象,并添加拦截器。源码如下:

protected HandlerExecutionChain getHandlerExecutionChain(Object handler, HttpServletRequest request) {
// 1、创建HandlerExecutionChain对象
HandlerExecutionChain chain = (handler instanceof HandlerExecutionChain ?
(HandlerExecutionChain) handler : new HandlerExecutionChain(handler)); // 2、添加拦截器
for (HandlerInterceptor interceptor : this.adaptedInterceptors) {
if (interceptor instanceof MappedInterceptor) {
MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor;
if (mappedInterceptor.matches(request)) {
chain.addInterceptor(mappedInterceptor.getInterceptor());
}
}
else {
chain.addInterceptor(interceptor);
}
}
return chain;
}

它会对初始化时配置的拦截器进行遍历:

  1. 如果是MappedInterceptor实现类,会根据匹配规则进行判断是否添加。
  2. 如果不是MappedInterceptor实现类,会直接添加。

2.3 添加跨域拦截器

添加跨域拦截器分为以下几个步骤:

  1. 判断是否存在跨域配置,或是否预检请求
  2. 获取handler级别的跨域配置
  3. 获取HandlerMapping级别的跨域配置
  4. 整合跨域配置
  5. 创建并添加跨域拦截器

2.3.1 判断是否存在跨域配置

AbstractHandlerMapping中,会判断handler是否CorsConfigurationSource的实现类(对于RequestMappingHandlerMapping而言,handlerHandlerMethod类型,所以第一个条件永远是false),以及是否存在HandlerMapping级别的跨域配置源:

protected boolean hasCorsConfigurationSource(Object handler) {
if (handler instanceof HandlerExecutionChain) {
handler = ((HandlerExecutionChain) handler).getHandler();
}
return (handler instanceof CorsConfigurationSource || this.corsConfigurationSource != null);
}

而在AbstractHandlerMethodMapping子抽象类中,会进一步判断是否存在handler级别(也就是@CrossOrigin级别)的跨域配置:

protected boolean hasCorsConfigurationSource(Object handler) {
return super.hasCorsConfigurationSource(handler) ||
(handler instanceof HandlerMethod &&
this.mappingRegistry.getCorsConfiguration((HandlerMethod) handler) != null);
}

2.3.2 判断是否是预检请求

org.springframework.web.cors.CorsUtils#isPreFlightRequest

public static boolean isPreFlightRequest(HttpServletRequest request) {
return (HttpMethod.OPTIONS.matches(request.getMethod()) &&
request.getHeader(HttpHeaders.ORIGIN) != null &&
request.getHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD) != null);
}

2.3.3 获取handler级别跨域配置

AbstractHandlerMapping中,会判断handler是否CorsConfigurationSource的实现类,从中获取handler级别的跨域配置。对于RequestMappingHandlerMapping而言,handlerHandlerMethod类型,所以第一个条件永远返回null

protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) {
Object resolvedHandler = handler;
if (handler instanceof HandlerExecutionChain) {
resolvedHandler = ((HandlerExecutionChain) handler).getHandler();
}
if (resolvedHandler instanceof CorsConfigurationSource) {
return ((CorsConfigurationSource) resolvedHandler).getCorsConfiguration(request);
}
return null;
}

AbstractHandlerMethodMapping子抽象类中,会从mappingRegistryrequest-handler缓存)中获取handler级别的跨域配置(在上篇文章中,我们有讲述过RequestMappingHandlerMapping如何缓存@CrossOrigin级别的跨域配置的):

protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) {
CorsConfiguration corsConfig = super.getCorsConfiguration(handler, request);
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
if (handlerMethod.equals(PREFLIGHT_AMBIGUOUS_MATCH)) {
return AbstractHandlerMethodMapping.ALLOW_CORS_CONFIG;
}
else {
CorsConfiguration corsConfigFromMethod = this.mappingRegistry.getCorsConfiguration(handlerMethod);
corsConfig = (corsConfig != null ? corsConfig.combine(corsConfigFromMethod) : corsConfigFromMethod);
}
}
return corsConfig;
}

2.3.4 获取HandlerMapping级别的跨域配置

AbstractHandlerMappingcorsConfigurationSource成员变量中,可以获取到HandlerMapping级别的跨域配置,该配置可以通过以下方式添加:

@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
// 添加HandlerMapping级别的跨域配置
}
}

2.3.5 整合跨域配置

在整合跨域配置过程中,有三种情况:

  1. 对于originsoriginPatternsallowedHeadersexposedHeadersmethods等列表属性,会获取全部。
  2. 对于allowCredentials,会优先获取方法级别的配置。
  3. 对于maxAge,会获取最大值。

具体可以查看相关源码:

public CorsConfiguration combine(@Nullable CorsConfiguration other) {
if (other == null) {
return this;
}
// Bypass setAllowedOrigins to avoid re-compiling patterns
CorsConfiguration config = new CorsConfiguration(this);
List<String> origins = combine(getAllowedOrigins(), other.getAllowedOrigins());
List<OriginPattern> patterns = combinePatterns(this.allowedOriginPatterns, other.allowedOriginPatterns);
config.allowedOrigins = (origins == DEFAULT_PERMIT_ALL && !CollectionUtils.isEmpty(patterns) ? null : origins);
config.allowedOriginPatterns = patterns;
config.setAllowedMethods(combine(getAllowedMethods(), other.getAllowedMethods()));
config.setAllowedHeaders(combine(getAllowedHeaders(), other.getAllowedHeaders()));
config.setExposedHeaders(combine(getExposedHeaders(), other.getExposedHeaders()));
Boolean allowCredentials = other.getAllowCredentials();
if (allowCredentials != null) {
config.setAllowCredentials(allowCredentials);
}
Long maxAge = other.getMaxAge();
if (maxAge != null) {
config.setMaxAge(maxAge);
}
return config;
}

2.3.6 创建并添加跨域拦截器

在这一步,对于预检请求,会创建HandlerExecutionChain;对于普通请求,会创建CorsInterceptor拦截器,并添加到首位:

protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request,
HandlerExecutionChain chain, @Nullable CorsConfiguration config) { if (CorsUtils.isPreFlightRequest(request)) {
HandlerInterceptor[] interceptors = chain.getInterceptors();
return new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
}
else {
chain.addInterceptor(0, new CorsInterceptor(config));
return chain;
}
}

3 AbstractHandlerMethodMapping

AbstractHandlerMethodMappingHandlerMethod请求映射的抽象基类,它的getHandlerInternal()方法定义了请求地址映射的核心流程:

  1. 解析请求路径
  2. 根据请求地址查找HandlerMethod

AbstractHandlerMethodMapping#getHandlerInternal

protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception {
// 1、解析请求地址
String lookupPath = initLookupPath(request);
this.mappingRegistry.acquireReadLock();
try {
// 2、根据请求地址查找HandlerMethod
HandlerMethod handlerMethod = lookupHandlerMethod(lookupPath, request);
return (handlerMethod != null ? handlerMethod.createWithResolvedBean() : null);
}
finally {
this.mappingRegistry.releaseReadLock();
}
}

3.1 解析请求路径

解析请求路径过程会获取当前请求的接口地址路径。

简单来说,会去除请求地址开头的contextPaht。例如在application.properties配置contextPath如下:

server.servlet.context-path=/context-path

此时,请求/context-path/test地址,经过initLookPath()方法处理,会返回/test为实际请求路径。

实际上,这也很容易理解。因为在RequestMappingHandlerMapping初始化pathLookup映射缓存时,就没有将contextPath考虑在内,那么在实际处理请求时,当然也要把contextPath去掉。

解析请求路径的作用也是为了方便直接从pathLookup映射缓存中获取对应的RequestMappingInfo信息。

AbstractHandlerMapping#initLookupPath源码如下:

protected String initLookupPath(HttpServletRequest request) {
if (usesPathPatterns()) {
request.removeAttribute(UrlPathHelper.PATH_ATTRIBUTE);
RequestPath requestPath = ServletRequestPathUtils.getParsedRequestPath(request);
String lookupPath = requestPath.pathWithinApplication().value();
return UrlPathHelper.defaultInstance.removeSemicolonContent(lookupPath);
}
else {
return getUrlPathHelper().resolveAndCacheLookupPath(request);
}
}

3.2 根据请求路径查找HandlerMethod

AbstractHandlerMethodMapping#lookupHandlerMethod方法中,会按如下步骤获取HandlerMethod

  1. 根据请求路径从pathLookup映射缓存查找对应的RequestMappingInfo列表。
  2. 根据RequestMappingInforegistry缓存中获取对应的MappingRegistration列表。
  3. 根据当前request,对MappingRegistration列表按匹配度进行排序。
  4. 从中取匹配度最高的HandlerMethod进行返回。

AbstractHandlerMethodMapping#lookupHandlerMethod源码如下:

protected HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) throws Exception {
List<Match> matches = new ArrayList<>();
List<T> directPathMatches = this.mappingRegistry.getMappingsByDirectPath(lookupPath);
if (directPathMatches != null) {
addMatchingMappings(directPathMatches, matches, request);
}
if (matches.isEmpty()) {
addMatchingMappings(this.mappingRegistry.getRegistrations().keySet(), matches, request);
}
if (!matches.isEmpty()) {
Match bestMatch = matches.get(0);
if (matches.size() > 1) {
Comparator<Match> comparator = new MatchComparator(getMappingComparator(request));
matches.sort(comparator);
bestMatch = matches.get(0);
if (logger.isTraceEnabled()) {
logger.trace(matches.size() + " matching mappings: " + matches);
}
if (CorsUtils.isPreFlightRequest(request)) {
for (Match match : matches) {
if (match.hasCorsConfig()) {
return PREFLIGHT_AMBIGUOUS_MATCH;
}
}
}
else {
Match secondBestMatch = matches.get(1);
if (comparator.compare(bestMatch, secondBestMatch) == 0) {
Method m1 = bestMatch.getHandlerMethod().getMethod();
Method m2 = secondBestMatch.getHandlerMethod().getMethod();
String uri = request.getRequestURI();
throw new IllegalStateException(
"Ambiguous handler methods mapped for '" + uri + "': {" + m1 + ", " + m2 + "}");
}
}
}
request.setAttribute(BEST_MATCHING_HANDLER_ATTRIBUTE, bestMatch.getHandlerMethod());
handleMatch(bestMatch.mapping, lookupPath, request);
return bestMatch.getHandlerMethod();
}
else {
return handleNoMatch(this.mappingRegistry.getRegistrations().keySet(), lookupPath, request);
}
}

3.2.1 查找pathLookup缓存

RequestMappingHandlerMapping请求地址映射的初始化过程中,会将@RequestMapping中的信息缓存到pathLookup中,其中该注解的请求路径作为key,该注解的各属性封装成RequestMappingInfo作为值。

需要注意的是,pathLookup的类型是MultiValueMap<String, T>,这里的T就是RequestMappingInfo

pathLookup的底层数据结构实际上是path-List<RequestMappingInfo>,这是因为请求路径不是接口的唯一指标,还包括请求头、请求方法等信息。

所以,一个请求地址实际上可能映射着多个HandlerMethod

例如,我们可以定义如下接口:

@RestController
public class SamePathController {
@GetMapping("/samePath")
public String get() {
return "get";
}
@PostMapping("/samePath")
public String post() {
return "post";
}
}

此时,GET localhost:8080/samePathPOST localhost:8080/samePath可以分别请求到对应的接口。

回到AbstractHandlerMethodMapping#getHandlerInternal源码,此时通过请求路径可以获取多个RequestMappingInfo

List<RequestMappingInfo> directPathMatches = this.mappingRegistry.getMappingsByDirectPath(lookupPath);

3.2.2 查找registry缓存

RequestMappingHandlerMapping请求地址映射的初始化过程中,会将接口的详细信息缓存到registry中,将上述RequestMappingInfo作为key,将RequestMappingInfoHanlderMethod等信息装成MappingRegistration作为值。

registry的类型是Map<T, MappingRegistration<T>>,这里的T指的是RequestMappingInfo

需要注意的是,由于RequestMappingInfo根据接口的@RequestMapping信息进行构造,如果存在@RequestMapping信息完全相同的多个接口,项目是无法启动的。

因此,RequestMappingInfo可以唯一定位到该接口,即RequestMappingInfoMappingRegistration是一一对应的。我们也可以将RequestMappingInfo等效于实际接口。

我们可以总结一下pathLookupregistry缓存的关系:

回到AbstractHandlerMethodMapping#getHandlerInternal源码:

if (directPathMatches != null) {
addMatchingMappings(directPathMatches, matches, request);
}
if (matches.isEmpty()) {
addMatchingMappings(this.mappingRegistry.getRegistrations().keySet(), matches, request);
}

存在两种情况:

  1. 如果在pathLookup缓存中找到对应List<RequestMappingInfo>,会进一步从该列表中查找更加匹配的RequestMappingInfo,并根据该RequestMappingregistry缓存中找到对应的MappingRegistration,封装成Match对象返回。
  2. 如果在pathLookup缓存中没有找到对应List<RequestMappingInfo>,会遍历registry缓存中的所有key,从中查找更加匹配的RequestMappingInfo,并根据该RequestMappingregistry缓存中找到对应的MappingRegistration,封装成Match对象返回。

具体流程对应的AbstractHandlerMethodMapping#addMatchingMappings源码如下:

private void addMatchingMappings(Collection<T> mappings, List<Match> matches, HttpServletRequest request) {
for (T mapping : mappings) {
T match = getMatchingMapping(mapping, request);
if (match != null) {
matches.add(new Match(match, this.mappingRegistry.getRegistrations().get(mapping)));
}
}
}

查找更加匹配的RequestMappingInfo对应的是RequestMappingInfoHandlerMapping#getMatchingMapping方法:

protected RequestMappingInfo getMatchingMapping(RequestMappingInfo info, HttpServletRequest request) {
return info.getMatchingCondition(request);
}

RequestMappingInfo#getMatchingCondition方法会对请求的methodsparamsconsumesproduces以及path进行校验,只有所有条件通过才会返回该RequestMappingInfo,否则会返回null。具体源码如下:

public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
if (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
if (headers == null) {
return null;
}
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
if (consumes == null) {
return null;
}
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);
if (produces == null) {
return null;
}
PathPatternsRequestCondition pathPatterns = null;
if (this.pathPatternsCondition != null) {
pathPatterns = this.pathPatternsCondition.getMatchingCondition(request);
if (pathPatterns == null) {
return null;
}
}
PatternsRequestCondition patterns = null;
if (this.patternsCondition != null) {
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, pathPatterns, patterns,
methods, params, headers, consumes, produces, custom, this.options);
}

通常情况下,通过这种判断可以筛选出唯一一个对应的RequestMappingInfo,除非是我们定义的接口比较特殊。

例如,我们定义接口如下:

@RestController
public class SamePathController {
@RequestMapping(value = "samePath", method = {RequestMethod.GET, RequestMethod.POST})
public String getAndPost() {
return "getAndPost";
}
@PostMapping("/samePath")
public String post() {
return "post";
}
}

此时,请求GET localhost:8080/samePath,可以筛选出来唯一一个定位到getAndPost()接口的RequestMappingInfo;请求POST localhost:8080/samePath,值可以筛选出两个分别定义到getAndPost()post()方法的RequestMappingInfo,因为它们的规则都满足条件,需要进一步筛选。

3.2.3 按匹配度排序

通常情况下,通过上述步骤可以筛选出唯一一个RequestMappingInfo

但是也有可能定义出条件重叠的接口(不推荐),此时会筛选出多个RequestMappingInfo。此时,需要根据某种规则进行匹配度排序。

RequestMappingInfo对于匹配度排序的规则是:

  1. 比较methodsparamsheaders等条件的长度:越短越具体,匹配度越高。
  2. 长度相等时,比较其他特殊规则:例如methods包含HEAD方法的匹配度高。

具体实现源码在RequestMappingInfo#compareTo

public int compareTo(RequestMappingInfo other, HttpServletRequest request) {
int result;
// Automatic vs explicit HTTP HEAD mapping
if (HttpMethod.HEAD.matches(request.getMethod())) {
result = this.methodsCondition.compareTo(other.getMethodsCondition(), request);
if (result != 0) {
return result;
}
}
result = getActivePatternsCondition().compareTo(other.getActivePatternsCondition(), request);
if (result != 0) {
return result;
}
result = this.paramsCondition.compareTo(other.getParamsCondition(), request);
if (result != 0) {
return result;
}
result = this.headersCondition.compareTo(other.getHeadersCondition(), request);
if (result != 0) {
return result;
}
result = this.consumesCondition.compareTo(other.getConsumesCondition(), request);
if (result != 0) {
return result;
}
result = this.producesCondition.compareTo(other.getProducesCondition(), request);
if (result != 0) {
return result;
}
// Implicit (no method) vs explicit HTTP method mappings
result = this.methodsCondition.compareTo(other.getMethodsCondition(), request);
if (result != 0) {
return result;
}
result = this.customConditionHolder.compareTo(other.customConditionHolder, request);
if (result != 0) {
return result;
}
return 0;
}

3.2.4 获取匹配度最高的HandlerMethod

通过上述步骤,我们最终获取到匹配度最高的RequestMappingInfo,直接取对应MappingRegistrationHandlerMethod成员变量返回即可。

RequestMappingHandlerMapping请求地址映射流程!的更多相关文章

  1. Spring MVC 处理一个请求的流程分析

    Spring MVC是Spring系列框架中使用频率最高的部分.不管是Spring Boot还是传统的Spring项目,只要是Web项目都会使用到Spring MVC部分.因此程序员一定要熟练掌握MV ...

  2. Volley HTTP库系列教程(2)Volley.newRequestQueue示例,发请求的流程,取消请求

    Sending a Simple Request Previous  Next This lesson teaches you to Add the INTERNET Permission Use n ...

  3. nginx的请求接收流程(二)

    在ngx_http_process_request_line函数中,解析完请求行之后,如果请求行的uri里面包含了域名部分,则将其保持在请求结构的headers_in成员的server字段,heade ...

  4. Spring MVC请求执行流程

    学习Spring MVC时间有点长了,但是最近打算找工作,需要重新了解下,所以又去温故知新了.Spring MVC就是用来写web的框架,简化你写web的一些不必要的流程,让程序员能专注于业务逻辑也就 ...

  5. 1.说一下的 dubbo 的工作原理?注册中心挂了可以继续通信吗?说说一次 rpc 请求的流程?

    作者:中华石杉 面试题 说一下的 dubbo 的工作原理?注册中心挂了可以继续通信吗?说说一次 rpc 请求的流程? 面试官心理分析 MQ.ES.Redis.Dubbo,上来先问你一些思考性的问题.原 ...

  6. redux请求数据流程

    redux请求数据流程 store里面的index.js文件 import {createStore,combineReducers,applyMiddleware} from "redux ...

  7. 07 flask源码剖析之用户请求过来流程

    07 Flask源码之:用户请求过来流程 目录 07 Flask源码之:用户请求过来流程 1.创建ctx = RequestContext对象 2. 创建app_ctx = AppContext对象 ...

  8. JSP请求响应流程入门介绍

    一个完整的jsp请求响应流程可以简单的使用下图表示: 过滤器:直观的了解,就是对请求做一个过滤作用,比如身份验证,验证不通过的不让他继续往下走 Servlet:请求处理中心,这个也是我们写业务逻辑的地 ...

  9. 《Symfony 5全面开发》教程04、Symfony处理http请求的流程

    当我们访问项目的/test路径时,浏览器会向我们的服务器端发送一个请求.我们打开浏览器的开发者工具,打开network选项卡. 在地址栏中敲击回车,浏览器向我们的服务器端发送了一个请求.请求的地址是1 ...

  10. 4.Spring Web MVC处理请求的流程

随机推荐

  1. PAT (Basic Level) Practice 1027 打印沙漏 分数 20

    本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个"*",要求按下列格式打印 ***** *** * *** *****   所谓"沙漏形状",是指 ...

  2. Wine 安装迅雷5.8.14.176

    测试过的系统版本:Kubuntu 22.04 测试过的Wine版本 Wine7.8 程序下载地址: https://pan.baidu.com/s/1pSgunVH3WtACssX5we3DdQ 提取 ...

  3. 【论文翻译】KLMo: Knowledge Graph Enhanced Pretrained Language Model with Fine-Grained Relationships

    KLMo:建模细粒度关系的知识图增强预训练语言模型 (KLMo: Knowledge Graph Enhanced Pretrained Language Model with Fine-Graine ...

  4. 一个好玩的deep learning Demo!

    对于生活中的熟悉的动物,我们人脑经过一次扫描,便可以得到该动物的物种!那么机器是如何识别这个图片上的动物是属于哪一物种呢? 本次实验借生活中最常见的猫和狗来探究其原理! 环境准备: tensorflo ...

  5. 华为云ubunbu部署.NetCore3.1项目(DDD商城)

    提前项目打包发布,文件传输工具Filezilla,注意是选择sftp协议,将publish文件传到/home文件夹下 第一步  .NetCoreSDK安装 微软官方的文档https://docs.mi ...

  6. 利用Hutool-(Java工具类)实现验证码校验

    目录 Hutool工具类介绍 Hutool实现验证码生成 测试验证码生成 其他样式的验证码 第一篇是纯利用现有JDK提供的绘图类(ImageIO)类制作,这个过程比较复杂且需要了解ImageIO类. ...

  7. 驱动开发:内核枚举PspCidTable句柄表

    在上一篇文章<驱动开发:内核枚举DpcTimer定时器>中我们通过枚举特征码的方式找到了DPC定时器基址并输出了内核中存在的定时器列表,本章将学习如何通过特征码定位的方式寻找Windows ...

  8. 基于雪花算法的增强版ID生成器

    sequence 基于雪花算法的增强版ID生成器 解决了时间回拨的问题 无需手动指定workId, 微服务环境自适应 可配置化 快速开始 依赖引入 <dependency> <gro ...

  9. (Java初学篇)IDEA项目新建流程和软件配置优化以及怎么彻底删除项目

    相信很多小伙伴们在初学 Java 时都会出现这样的情况,就是在网上一顿搜索加捣鼓终于把 JDK 和IDEA 这两款软件安装配置好,但是发现面对这个陌生的软件此时却无从下手,那么接下来我就给大家简单地介 ...

  10. SDOI2017树点染色

    题目链接 发现1操作很像lct中的access,然后它每次染的又是一个新颜色,因此同一个颜色就在同一颗splay里了,且一个点到根的权值val[i]也就是到根路径上虚边的个数,然后看access时会对 ...