Mybatis源码01-SpringBoot启动时mybatis加载过程
使用了mybatis这么久还没有具体探究了SpringBoot启动时候对于mybatis是怎么加载的。
1、首先项目构建时我们会引入相关的依赖:
<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.1</version></dependency><!--MyBatis依赖--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.1</version></dependency><!--mysql驱动--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.9</version></dependency>
mybatis-spring-boot-starter这个包声明了自动构建MyBatis的一些配置,以及创建SqlSessionFactory的类
1 MybatisAutoConfiguration
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {SqlSessionFactoryBean factory = new SqlSessionFactoryBean();// 设置数据源factory.setDataSource(dataSource);factory.setVfs(SpringBootVFS.class);// 加载 MyBatis 全局配置文件 例:如果配置了 mybatis.config-location(如 classpath:mybatis-config.xml),则加载该全局配置文件。if (StringUtils.hasText(this.properties.getConfigLocation())) {factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));}// 将 application.yml 中的 MyBatis 配置(以 mybatis.configuration.* 开头的属性)应用到 SqlSessionFactoryapplyConfiguration(factory);if (this.properties.getConfigurationProperties() != null) {factory.setConfigurationProperties(this.properties.getConfigurationProperties());}// 注册 MyBatis 插件 例如分页插件if (!ObjectUtils.isEmpty(this.interceptors)) {factory.setPlugins(this.interceptors);}// 多数据库支持if (this.databaseIdProvider != null) {factory.setDatabaseIdProvider(this.databaseIdProvider);}// 设置类型别名扫描包if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());}// 设置类型别名的父类if (this.properties.getTypeAliasesSuperType() != null) {factory.setTypeAliasesSuperType(this.properties.getTypeAliasesSuperType());}// 设置类型处理器扫描包if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());}// 注册自定义类型处理器if (!ObjectUtils.isEmpty(this.typeHandlers)) {factory.setTypeHandlers(this.typeHandlers);}// 加载sql mapper.xml文件路径 路径通过 mybatis.mapper-locations 配置。if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {factory.setMapperLocations(this.properties.resolveMapperLocations());}// 动态 SQL 语言驱动Set<String> factoryPropertyNames = Stream.of(new BeanWrapperImpl(SqlSessionFactoryBean.class).getPropertyDescriptors()).map(PropertyDescriptor::getName).collect(Collectors.toSet());Class<? extends LanguageDriver> defaultLanguageDriver = this.properties.getDefaultScriptingLanguageDriver();if (factoryPropertyNames.contains("scriptingLanguageDrivers") && !ObjectUtils.isEmpty(this.languageDrivers)) {// Need to mybatis-spring 2.0.2+factory.setScriptingLanguageDrivers(this.languageDrivers);if (defaultLanguageDriver == null && this.languageDrivers.length == 1) {defaultLanguageDriver = this.languageDrivers[0].getClass();}}if (factoryPropertyNames.contains("defaultScriptingLanguageDriver")) {// Need to mybatis-spring 2.0.2+factory.setDefaultScriptingLanguageDriver(defaultLanguageDriver);}// 调用 SqlSessionFactoryBean 的 getObject() 方法,生成最终的 SqlSessionFactory 实例。return factory.getObject();}
作用
**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">sqlSessionFactory</font>**
方法的主要目的是 自动构建并配置 MyBatis 的**** **<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">SqlSessionFactory</font>**
****实例,使得开发者无需手动编写大量 XML 或 Java 配置即可集成 MyBatis。该方法通过以下步骤实现:
- 依赖注入关键组件
利用 Spring Boot 的自动装配机制,注入必要的依赖(如**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">DataSource</font>**
、MyBatis 配置属性等)。 - 应用 MyBatis 全局配置
加载**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">mybatis-config.xml</font>**
(如果存在)或通过属性配置 MyBatis 的行为(如缓存、插件等)。 - 配置 Mapper 文件位置
扫描并注册 Mapper 接口或 XML 文件,使其能被 MyBatis 识别。 - 整合 Spring 事务管理
确保**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">SqlSessionFactory</font>**
与 Spring 的事务管理器兼容。
二、 SqlSessionFactoryBean
factory.getObject() 创建**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">sqlSessionFactory</font>**
最终在buildSqlSessionFactory这个方法完成创建。
protected SqlSessionFactory buildSqlSessionFactory() throws Exception {final Configuration targetConfiguration;XMLConfigBuilder xmlConfigBuilder = null;if (this.configuration != null) {// 使用已经有的Configuration 对象targetConfiguration = this.configuration;// 合并全局变量(configurationProperties)if (targetConfiguration.getVariables() == null) {targetConfiguration.setVariables(this.configurationProperties);} else if (this.configurationProperties != null) {targetConfiguration.getVariables().putAll(this.configurationProperties);}} else if (this.configLocation != null) {// 通过 XML 配置文件初始化 ConfigurationxmlConfigBuilder = new XMLConfigBuilder(this.configLocation.getInputStream(), null, this.configurationProperties);targetConfiguration = xmlConfigBuilder.getConfiguration();} else {LOGGER.debug(() -> "Property 'configuration' or 'configLocation' not specified, using default MyBatis Configuration");// 创建默认 Configuration 并设置全局变量targetConfiguration = new Configuration();Optional.ofNullable(this.configurationProperties).ifPresent(targetConfiguration::setVariables);}/*** 设置核心扩展组件* ObjectFactory:控制对象(如 POJO)的实例化方式。* ObjectWrapperFactory:用于包装返回对象(如集合)。* VFS:虚拟文件系统实现(如处理 Spring Boot 内嵌 JAR 中的资源)*/Optional.ofNullable(this.objectFactory).ifPresent(targetConfiguration::setObjectFactory);Optional.ofNullable(this.objectWrapperFactory).ifPresent(targetConfiguration::setObjectWrapperFactory);Optional.ofNullable(this.vfs).ifPresent(targetConfiguration::setVfsImpl);// 扫描包下的类注册别名if (hasLength(this.typeAliasesPackage)) {scanClasses(this.typeAliasesPackage, this.typeAliasesSuperType).stream().filter(clazz -> !clazz.isAnonymousClass()).filter(clazz -> !clazz.isInterface()).filter(clazz -> !clazz.isMemberClass()).forEach(targetConfiguration.getTypeAliasRegistry()::registerAlias);}// 显式注册类型别名if (!isEmpty(this.typeAliases)) {Stream.of(this.typeAliases).forEach(typeAlias -> {targetConfiguration.getTypeAliasRegistry().registerAlias(typeAlias);LOGGER.debug(() -> "Registered type alias: '" + typeAlias + "'");});}// 注册插件if (!isEmpty(this.plugins)) {Stream.of(this.plugins).forEach(plugin -> {targetConfiguration.addInterceptor(plugin);LOGGER.debug(() -> "Registered plugin: '" + plugin + "'");});}// 处理类型处理器if (hasLength(this.typeHandlersPackage)) {scanClasses(this.typeHandlersPackage, TypeHandler.class).stream().filter(clazz -> !clazz.isAnonymousClass()).filter(clazz -> !clazz.isInterface()).filter(clazz -> !Modifier.isAbstract(clazz.getModifiers())).forEach(targetConfiguration.getTypeHandlerRegistry()::register);}if (!isEmpty(this.typeHandlers)) {Stream.of(this.typeHandlers).forEach(typeHandler -> {targetConfiguration.getTypeHandlerRegistry().register(typeHandler);LOGGER.debug(() -> "Registered type handler: '" + typeHandler + "'");});}if (!isEmpty(this.scriptingLanguageDrivers)) {Stream.of(this.scriptingLanguageDrivers).forEach(languageDriver -> {targetConfiguration.getLanguageRegistry().register(languageDriver);LOGGER.debug(() -> "Registered scripting language driver: '" + languageDriver + "'");});}Optional.ofNullable(this.defaultScriptingLanguageDriver).ifPresent(targetConfiguration::setDefaultScriptingLanguage);// 多数据库支持if (this.databaseIdProvider != null) {// fix #64 set databaseId before parse mapper xmlstry {targetConfiguration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));} catch (SQLException e) {throw new NestedIOException("Failed getting a databaseId", e);}}Optional.ofNullable(this.cache).ifPresent(targetConfiguration::addCache);// 解析 XML 配置文件if (xmlConfigBuilder != null) {try {xmlConfigBuilder.parse();LOGGER.debug(() -> "Parsed configuration file: '" + this.configLocation + "'");} catch (Exception ex) {throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);} finally {ErrorContext.instance().reset();}}// SpringManagedTransactionFactory 确保 MyBatis 事务由 Spring 管理。targetConfiguration.setEnvironment(new Environment(this.environment,this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,this.dataSource));// 加载和解析 Mapper XML文件if (this.mapperLocations != null) {if (this.mapperLocations.length == 0) {LOGGER.warn(() -> "Property 'mapperLocations' was specified but matching resources are not found.");} else {for (Resource mapperLocation : this.mapperLocations) {if (mapperLocation == null) {continue;}try {XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments());xmlMapperBuilder.parse();} catch (Exception e) {throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);} finally {ErrorContext.instance().reset();}LOGGER.debug(() -> "Parsed mapper file: '" + mapperLocation + "'");}}} else {LOGGER.debug(() -> "Property 'mapperLocations' was not specified.");}// 构建 SqlSessionFactoryreturn this.sqlSessionFactoryBuilder.build(targetConfiguration);}
图例解析:
三、 XMLMapperBuilder
XMLMapperBuilder继承于BaseBuilder。他们对于XML文件本身技术上的加载和解析都委托给了XPathParser,最终用的是jdk自带的xml解析器而非第三方比如dom4j,底层使用了xpath方式进行节点解析。new XPathParser(reader, true, props, new XMLMapperEntityResolver())的参数含义分别是Reader,是否进行DTD 校验,属性配置,XML实体节点解析器。
entityResolver比较好理解,跟Spring的XML标签解析器一样,有默认的解析器,也有自定义的比如tx,dubbo等,主要使用了策略模式,在这里mybatis硬编码为了XMLMapperEntityResolver。
XMLMapperEntityResolver的定义如下
public class XMLMapperEntityResolver implements EntityResolver {private static final String IBATIS_CONFIG_SYSTEM = "ibatis-3-config.dtd";private static final String IBATIS_MAPPER_SYSTEM = "ibatis-3-mapper.dtd";private static final String MYBATIS_CONFIG_SYSTEM = "mybatis-3-config.dtd";private static final String MYBATIS_MAPPER_SYSTEM = "mybatis-3-mapper.dtd";private static final String MYBATIS_CONFIG_DTD = "org/apache/ibatis/builder/xml/mybatis-3-config.dtd";private static final String MYBATIS_MAPPER_DTD = "org/apache/ibatis/builder/xml/mybatis-3-mapper.dtd";/** Converts a public DTD into a local one * 将公共的DTD转换为本地模式* * @param publicId The public id that is what comes after "PUBLIC"* @param systemId The system id that is what comes after the public id.* @return The InputSource for the DTD* * @throws org.xml.sax.SAXException If anything goes wrong*/@Overridepublic InputSource resolveEntity(String publicId, String systemId) throws SAXException {try {if (systemId != null) {String lowerCaseSystemId = systemId.toLowerCase(Locale.ENGLISH);if (lowerCaseSystemId.contains(MYBATIS_CONFIG_SYSTEM) || lowerCaseSystemId.contains(IBATIS_CONFIG_SYSTEM)) {return getInputSource(MYBATIS_CONFIG_DTD, publicId, systemId);} else if (lowerCaseSystemId.contains(MYBATIS_MAPPER_SYSTEM) || lowerCaseSystemId.contains(IBATIS_MAPPER_SYSTEM)) {return getInputSource(MYBATIS_MAPPER_DTD, publicId, systemId);}}return null;} catch (Exception e) {throw new SAXException(e.toString());}}private InputSource getInputSource(String path, String publicId, String systemId) {InputSource source = null;if (path != null) {try {InputStream in = Resources.getResourceAsStream(path);source = new InputSource(in);source.setPublicId(publicId);source.setSystemId(systemId); } catch (IOException e) {// ignore, null is ok}}return source;}}
该类的核心作用是通过本地加载 DTD/XSD 验证文件,避免 XML 解析时从网络下载外部资源
继续往下看
public XPathParser(Reader reader, boolean validation, Properties variables, EntityResolver entityResolver) {commonConstructor(validation, variables, entityResolver);this.document = createDocument(new InputSource(reader));}private void commonConstructor(boolean validation, Properties variables, EntityResolver entityResolver) {this.validation = validation;this.entityResolver = entityResolver;this.variables = variables;XPathFactory factory = XPathFactory.newInstance();this.xpath = factory.newXPath();}
主要看 createDocument
private Document createDocument(InputSource inputSource) {// important: this must only be called AFTER common constructortry {DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();factory.setValidating(validation);//设置由本工厂创建的解析器是否支持XML命名空间 TODO 什么是XML命名空间factory.setNamespaceAware(false);factory.setIgnoringComments(true);factory.setIgnoringElementContentWhitespace(false);//设置是否将CDATA节点转换为Text节点factory.setCoalescing(false);//设置是否展开实体引用节点,这里应该是sql片段引用的关键factory.setExpandEntityReferences(true);DocumentBuilder builder = factory.newDocumentBuilder();//设置解析mybatis xml文档节点的解析器,也就是上面的XMLMapperEntityResolverbuilder.setEntityResolver(entityResolver);builder.setErrorHandler(new ErrorHandler() {@Overridepublic void error(SAXParseException exception) throws SAXException {throw exception;}@Overridepublic void fatalError(SAXParseException exception) throws SAXException {throw exception;}@Overridepublic void warning(SAXParseException exception) throws SAXException {}});return builder.parse(inputSource);} catch (Exception e) {throw new BuilderException("Error creating document instance. Cause: " + e, e);}}
主要是根据mybatis自身需要创建一个文档解析器,然后调用parse将输入input source解析为DOM XML文档并返回。
得到XPathParser实例之后,就调用另一个使用XPathParser作为配置来源的重载构造函数了,如下:
private XMLConfigBuilder(XPathParser parser, String environment, Properties props) {super(new Configuration());ErrorContext.instance().resource("SQL Mapper Configuration");this.configuration.setVariables(props);this.parsed = false;this.environment = environment;this.parser = parser;}
其中调用了父类BaseBuilder的构造器(主要是设置类型别名注册器,以及类型处理器注册器):
XMLConfigBuilder创建完成之后,SqlSessionFactoryBean调用xmlMapperBuilder.parse();创建Configuration。所有,真正Configuration构建逻辑就在xmlMapperBuilder.parse();里面,如下所示:
public void parse() {if (!configuration.isResourceLoaded(resource)) {configurationElement(parser.evalNode("/mapper"));configuration.addLoadedResource(resource);bindMapperForNamespace();}parsePendingResultMaps();parsePendingCacheRefs();parsePendingStatements();}
1. 检查资源是否已加载 (**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">configuration.isResourceLoaded(resource)</font>**
)
- 作用:
确保同一 Mapper XML 文件不会被重复解析(如多线程环境或错误配置时)。 - 实现原理:
**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">configuration</font>**
对象维护了一个**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">Set<String> loadedResources</font>**
,存储所有已加载的 XML 文件路径(如**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">com/example/UserMapper.xml</font>**
)。
2. 解析**** **<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><mapper></font>**
****根标签 (**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">configurationElement(...)</font>**
)
- 作用:
解析 XML 文件中**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><mapper></font>**
标签下的所有配置元素,包括:**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><cache></font>**
:二级缓存配置**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><resultMap></font>**
:结果集映射**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><sql></font>**
:可重用的 SQL 片段**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><select|insert|update|delete></font>**
:SQL 语句定义
实现逻辑:
- java复制下载
private void configurationElement(XNode context) {// 获取 namespace 属性(必须对应 Mapper 接口的全限定名)String namespace = context.getStringAttribute("namespace");if (namespace == null || namespace.isEmpty()) {throw new BuilderException("Mapper's namespace cannot be empty");}builderAssistant.setCurrentNamespace(namespace);// 解析缓存配置cacheRefElement(context.evalNode("cache-ref"));cacheElement(context.evalNode("cache"));// 解析所有 <resultMap>resultMapElements(context.evalNodes("/mapper/resultMap"));// 解析所有 <sql> 片段sqlElement(context.evalNodes("/mapper/sql"));// 解析所有 SQL 语句(select|insert|update|delete)buildStatementFromContext(context.evalNodes("select|insert|update|delete"));
}
3. 标记资源为已加载 (**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">addLoadedResource</font>**
)
- 目的:
将当前 XML 文件路径(如**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">com/example/UserMapper.xml</font>**
)添加到**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">loadedResources</font>**
集合,后续再次解析同一文件时会直接跳过。
4. 绑定 Mapper 接口 (**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">bindMapperForNamespace</font>**
)
- 作用:
将 XML 中**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">namespace</font>**
属性指定的接口(如**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">com.example.UserMapper</font>**
)注册到 MyBatis,使得接口方法与 XML 中的 SQL 语句关联。
实现逻辑:
- java复制下载
private void bindMapperForNamespace() {// 获取 namespace 对应的接口类Class<?> boundType = Resources.classForName(namespace);// 将接口添加到 MapperRegistryif (boundType != null && !configuration.hasMapper(boundType)) {configuration.addMapper(boundType);}
}
- 关键点:
MyBatis 通过动态代理为接口生成实现类,将方法调用映射到 XML 中的 SQL 语句。
5. 处理延迟解析的依赖项
- 背景:
某些配置项(如**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><resultMap></font>**
)可能依赖其他尚未解析的资源(如其他 XML 文件中的定义),需要延迟解析。 - 具体方法:
**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">parsePendingResultMaps()</font>**
解析之前未能完全初始化的**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">ResultMap</font>**
(例如,引用了其他**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">ResultMap</font>**
的情况)。**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">parsePendingCacheRefs()</font>**
处理**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);"><cache-ref></font>**
标签引用的其他命名空间的缓存配置。**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">parsePendingStatements()</font>**
完成所有 SQL 语句的最终解析(如确认引用的**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">resultMap</font>**
或**<font style="color:rgb(64, 64, 64);background-color:rgb(236, 236, 236);">parameterType</font>**
已存在)。
相关文章:
Mybatis源码01-SpringBoot启动时mybatis加载过程
使用了mybatis这么久还没有具体探究了SpringBoot启动时候对于mybatis是怎么加载的。 1、首先项目构建时我们会引入相关的依赖: <dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</arti…...
springCloud/Alibaba常用中间件全集(上)
文章目录 SpringCloud:一、Consul:服务注册与发现1、下载Consul2、运行Consul3、服务注册①. 导入依赖②. 配置yml③. 启动类添加Consul的启动服务发现注解④. 解决 **硬编码** 问题⑤. 此时便可以将IP地址改为服务名 4、服务配置与刷新①. 引入Consul-Config依赖②. 修改boots…...
嵌入式单片机通过ESP8266连接物联网实验
第一:通过手机APP远程监控和控制 ESP8266驱动RST低电平触发复位,平时需要跟EN一样分别接10k拉高到3.3V 如果是12E/F的话管脚比较多,GPIO15也要接个1K到地 烧录时GPIO要接地,正常工作时将其拉高或者悬空 主要使用串口通信,烧录固件也是通过串口,烧录时,启动烧录程序后…...
Visio导出清晰图片步骤
在Visio里画完图之后如何导出清晰的图片?👇 ①左上角单击【文件】 ②导出—更改文件类型—PNG/JPG ③分辨率选择【打印机】,大小选择【源】,即可。 ④选择保存位置并命名 也可以根据自己需要选择是否需要【透明底】哈。 选PNG 然…...
速查手册:TA-Lib 超过150种量化技术指标计算全解 - 1. Overlap Studies(重叠指标)
速查手册:TA-Lib 超过150种量化技术指标计算全解 - 1. Overlap Studies(重叠指标) TA-Lib(Technical Analysis Library)是广泛使用的金融技术分析库,实现了超过150种技术指标计算函数,适用于股票…...
大模型Rag - 如何评估Rag
一.RAG流程与评估标准补充 RAG(Retrieval-Augmented Generation)是一种结合检索与生成的问答架构。为了确保系统效果,需要从以下三个角度对其评估: 回顾RAG流程 用户提出问题 → 系统检索相关上下文 → 基于上下文由大语言模型…...
复习JUC的总结笔记
JUC基础 调用Thread的start方法会调用start0,start0会调用该Thread类的run方法。Thread类如果传入了Runnable,run方法里会调用Runnable的run方法,如果没有传入,则什么也不会做。也可以通过重写Thread的run方法,让start…...
基于MTF的1D-2D-CNN-GRU-Attention时序图像多模态融合的故障识别,适合研究学习(Matlab完整源码和数据),附模型研究报告
基于MTF的1D-2D-CNN-GRU-Attention时序图像多模态融合的故障识别,适合研究学习(Matlab完整源码和数据),附模型研究报告 目录 基于MTF的1D-2D-CNN-GRU-Attention时序图像多模态融合的故障识别,适合研究学习(…...
5G 毫米波滤波器的最优选择是什么?
新的选择有很多,但到目前为止还没有明确的赢家。 蜂窝电话技术利用大量的带带,为移动用途提供不断增加的带宽。 其中的每一个频带都需要透过滤波器将信号与其他频带分开,但目前用于手机的滤波器技术可能无法扩展到5G所规划的全部毫米波&#…...
构造函数和析构函数
概念:对象的初始化和清理是非常重要的,一个对象在使用之前,需要进行初始化,使用完成后也需要及时清理数据,简单来说构造函数时用来初始化成员属性的,析构函数时用来清理数据的。 C中利用构造函数和析构函数…...
卷积神经网络(CNN)详解
文章目录 引言1.卷积神经网络(CNN)的诞生背景2.卷积神经网络(CNN)介绍2.1 什么是卷积神经网络?2.2 卷积神经网络(CNN)的基本特征2.2.1 局部感知(Local Connectivity)2.2.…...
NoSQl注入学习
文章目录 什么是NOSQL相关概念数据库文档集合 MongoDB 基础语法创建数据库创建集合插入文档更新文档查询文档 Nosql注入PHP 中的 MongoDB 注入重言式注入联合查询注入JavaScript 注入布尔盲注 Nodejs 中的 MongoDB 注入 从一道题中学习nosql注入 参考: Nosql 注入从…...
借助LlamaIndex实现简单Agent
借助LlamaIndex实现简单Agent 1 简介 智能体的构建发展是一个趋势,借助LlamaIndex简单实现Agent。本文主要借助LlamaIndex中的FunctionTool和Workflow。Workflow是使用事件流的方法实现。 2 构建公共类 由于LlamaIndex中的OpenAI无法直接连接国内大模型…...
MCGS昆仑通太屏笔记
4.3寸:4013ef/e1 7寸:7032kw 特点: 如果是使用组态屏进行调试使用,选择com1如果是实际项目使用,选择com2 操作步骤: 先创建设备窗口,再创建用户界面 在设备窗口界面,依次设置如下…...
纯FPGA控制AD9361的思路和实现之一 概述
我们知道PS通过内存映射方式方式用户的IP,具体是将用户的逻辑做成AXI_LITE_SALVE外设,PS做为AXI_LITE_MASTER去控制。 在ZYNQ系统中存在PS所以这个架构和思路很流行,ADI出的配置软件无线电子板的DEMO基本都是基于这样的架构。比如下图【上截…...
北斗短报文终端与5G融合:构建空天地海一体化通信新生态
随着北斗三号全球组网完成,短报文通信服务从区域覆盖迈向全球通达,其与5G技术的深度融合,正开创“空天地海一体化”通信新时代。深圳作为全国北斗产业高地,汇聚了遨游通讯等领军企业,其推出的北斗短报文终端通过技术创…...
Meteonorm8-免费使用教程(详细教程-免费)
Meteonorm介绍 Meteonorm 8 是一款专业的气象数据生成软件,广泛应用于太阳能、建筑能效、农业气候研究等领域。它提供全球范围内高精度的气象数据,支持多种数据源和插值方法,帮助用户获取特定地点的长期气象统计信息。 Meteonorm核心功能 …...
nohup的使用
最近远程连接服务器跑程序的时候,总是碰到本地电脑息屏或者ssh断开导致程序中断,往往一觉醒来不是程序跑完了而是因为各种原因本地中断了。为此想到了nohup这个命令,可以让程序在我本地电脑关机后也可以在远端服务器上面运行。 命令如下&…...
如何查看HTTP状态码?
目录 一、HTTP状态码查看方法 1. 浏览器开发者工具 2. 命令行工具 3. 服务器日志分析 二、HTTP状态码分类与核心含义 1. 信息类(1xx) 2. 成功类(2xx) 3. 重定向类(…...
2025.04.19【Chord diagram】| 弦图绘制技巧大全
Customization Apply customization to the circular chart: color, background, track height and more. Chart types Learn how to use other chart types like line chart, barcharts, vertical ablines and more. 文章目录 CustomizationChart types 什么是弦图ÿ…...
解码 Web Service:从技术原理到应用场景的深度剖析
Web Service 是一种基于网络的、分布式的计算技术,它允许不同的应用程序之间通过网络进行通信和交互。以下是关于 Web Service 的详细介绍: 一、定义与概念 Web Service 是一种可以通过 Web 协议(如 HTTP)进行访问的软件组件&am…...
hackmyvm-airbind
收集信息 arp-scan -l nmap -sS -v 192.168.195.162 访问扫描到的ip,直接跳转到登录页面,利用admin/admin弱口令登录 在settings.php中找到一处文件上传,上传一句话木马,上传成功 反弹shell 上传php-reverse-shell.php 抓包&am…...
[HCIP] OSPF 综合实验
题目 实验需求 1.R5为TSP,其上只能配置IP地址; R5与其他所有直连设备间均使用公有IP;环回地址为100.1.1.1/32 2.R4设备为企业出口路由器 3.整个OSPF环境IP基于172.16.0.0/16划分; 4.所有设备均可访问R5的环回; 5…...
arkTs:使用setTimeout / setInterval 实现透明度切换的轮播图
使用setTimeout / setInterval 实现透明度切换的轮播图 1 主要内容说明1.1 setTimeout1.2 setInterval1.3 表格 2 举例说明2.1 图片变化的内容说明2.2 源码相关内容说明2.3 源码A2.4源码A的运行效果展示2.4.1 效果截图2.4.2 效果视频 3.结语4.定位日期 1 主要内容说明 1.1 set…...
苍穹外卖项目中所涉及到的测试内容
1.使用JWT令牌封装用户令牌,并且设置相应的拦截器校验JWT的有效性,从而确保了项目的安全可靠 1.基本功能测试: 验证合法JWT是否能够正常通过拦截器的校验 验证非法的JWT能否正常通过拦截器的校验 2.可靠性测试: 3.易用性测试 …...
案例驱动的 IT 团队管理:创新与突破之路:第五章 创新管理:从机制设计到文化养成-5.2 技术决策民主化-5.2.3草根创新的孵化土壤构建
👉 点击关注不迷路 👉 点击关注不迷路 👉 点击关注不迷路 文章大纲 草根创新的孵化土壤构建:IT团队技术决策民主化的底层实践1. 背景与挑战:传统技术决策体系的失效1.1 行业现状与痛点1.2 草根创新的价值潜力 2. 机制设…...
探秘Python 工匠:案例、技巧与工程实践:解锁Python进阶的通关秘籍
重要的放前面 Python 工匠:案例、技巧与工程实践 探秘Python 工匠:案例、技巧与工程实践:解锁Python进阶的通关秘籍 在Python的编程世界中,从入门小白到技术大牛的进阶之路往往充满挑战。Python工匠:案例、技巧与工…...
【langchain4j】Springboot如何接入大模型以及实战开发-AI问答助手(一)
langchain4j介绍 官网地址:https://docs.langchain4j.dev/get-started langchain4j可以说是java和spring的关系,spring让我们开发java应用非常简单,那么langchain4j对应的就是java开发ai的 “Spring” 他集成了AI应用的多种场景,…...
解决Windows update服务启动拒绝访问的问题 | wuauserv 注册表拒绝访问的方法
在某些情况下,为了配置系统更新相关服务(例如禁用 Windows 自动更新),我们需要更改注册表中 wuauserv 项的权限。本教程将带你一步步操作,成功获取并修改权限。 修改注册表路径: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wuauserv 步骤一:打开注册表编辑…...
精益数据分析(5/126):解锁创业成功的关键密码
精益数据分析(5/126):解锁创业成功的关键密码 大家好!我一直坚信在技术与商业不断融合的当下,持续学习是保持进步的唯一途径。之前我们一起探讨了《精益数据分析》的部分内容,今天咱们接着深入学习&#x…...
Cribl 优化EC2 ip-host-region 数据
We’ve seen examples of using the magical powers of regex to customize Functions, extract fields, and filter events in real time. In this section, we’ll show you how to sprinkle your Lookups with regex magic. Lets walk through a Pipeline that demonstrates…...
【java实现+4种变体完整例子】排序算法中【桶排序】的详细解析,包含基础实现、常见变体的完整代码示例,以及各变体的对比表格
以下是桶排序的详细解析,包含基础实现、常见变体的完整代码示例,以及各变体的对比表格: 一、桶排序基础实现 原理 将数据分到有限数量的桶中,每个桶内部使用其他排序算法(如插入排序或快速排序)…...
栈(c++)
今天介绍两种在c中写“栈”方法 1. #include <bits/stdc.h> using namespace std;class mystack { private:int a[1000];int curr -1; public:void push(int);void pop();int top();bool empyt();int size(); };int main() {mystack n;while(true){int a;cout<<&…...
GraphRAG与RAG的区别和原理简介
第一章 图谱与向量的共生逻辑 1.1 知识载体的局限性 向量空间模型虽能高效捕捉文本语义相似性,却无法解析知识的深层关联。例如,当用户询问“特斯拉4680电池与续航里程的关系”,向量检索可能仅返回技术参数片段,而无法解释化学成…...
vue2技术练习-开发了一个宠物相关的前端静态商城网站-宠物商城网站
为了尽快学习掌握相关的前端技术,最近又实用 vue2做了一个宠物行业的前端静态网站商城。还是先给大家看一下相关的网站效果: 所以大家如果想快速的学习或者掌握一门编程语言,最好的方案就是通过学习了基础编程知识后,就开始利用…...
[每周一更]-(第140期):sync.Pool 使用详解:性能优化的利器
文章目录 一、什么是 sync.Pool?二、sync.Pool 的基本作用三、sync.Pool 的主要方法四、sync.Pool 的内部工作原理五、sync.Pool 适用场景六、使用示例示例 1:基本使用输出示例:示例 2:并发使用 七、一个基于 sync.Pool 的 **Benc…...
Prompt-Tuning 提示词微调
1. Hard Prompt 定义: Hard prompt 是一种更为具体和明确的提示,要求模型按照给定的信息生成精确的结果,通常用于需要模型提供准确答案的任务. 原理: Prompt Tuning原理如下图所示:冻结主模型全部参数,在…...
sqli-labs之Less-7 GET注入写shell
验证注入点:单引号报错,)) 根据提示,是想让我们试试写shell 第一个条件 secure_file_priv 写shell即MySQL需要对外写文件,但默认MySQL是不允许outfile来导出数据的,先动手在MySQL确认一下。 MySQL特性,se…...
数据库基础-B+树
查询类型 全表扫描,不提供索引,扫描所有集合中的数据。根据指定key值查询指定点范围查询,在指定区间内查询 有很多方法能够进行快速扫面数据,但是再快复杂度也是O(N),我们的目标是想办法将查询复杂度降低到O(logN)。…...
智能语音备忘录:SpeechRecognition与gTTS的奇妙融合
引言:智能语音备忘录的时代已经到来 在这个信息爆炸的时代,我们每天需要处理大量的事务和信息。传统的文字记录方式虽然可靠,但在效率上往往难以满足快节奏生活的需求。想象一下,如果你能在驾车、散步或是灵感突现的任何时刻&…...
C++项目 —— 基于多设计模式下的同步异步日志系统(3)(日志器类)
C项目 —— 基于多设计模式下的同步&异步日志系统(3)(日志器类) 整体思想设计日志消息的构造C语言式的不定参函数的作用函数的具体实现逻辑1. 日志等级检查2. 初始化可变参数列表3. 格式化日志消息4. 释放参数列表5. 序列化和…...
2025/4/19 数据库的流程控制函数
单行函数_流程函数 要点: 流程处理函数可以根据不同的条件 执行不同的处理流程 可以在SQL语句中实现不同的条件选择,MySQL中的流程处理函数主要包括if() ifnull() 和 case() 函数 多行函数_聚合函数 和单行函数的区别: 单行函数是作用在每一行 最终结果可能是多行结果 多行…...
代码随想录打家劫舍+树形DP入门
动态规划part07 198.打家劫舍 视频讲解:https://www.bilibili.com/video/BV1Te411N7SX https://programmercarl.com/0198.%E6%89%93%E5%AE%B6%E5%8A%AB%E8%88%8D.html dp数组:进入房屋i能够偷得得最大金额dp[i]递推公式:根据不相邻原则…...
Http基础
目录 定义 一、请求部分(Request) 1. 请求行(Request Line) 常见请求方法: 2. 请求头(Request Headers) 3. 请求体(Request Body) 二、响应部分(Respo…...
【Unity】bug记录——部分物体突然不受animator控制
博主烘焙完灯光后突然发现有的物体的动画失效了,不会动,测试发现是因为勾了static(但是有些勾了static的物体就没事),修改static为Contribute GI Static(只针对光照静态)就行...
Zephyr、FreeRTOS、RT-Thread 邮箱(Mailbox)对比分析
一、核心特性对比 特性ZephyrFreeRTOSRT-Thread消息类型支持指针或4字节数据(依赖架构)仅支持指针传递支持任意数据类型(需指定消息长度)容量固定容量(静态初始化配置)动态容量(基于队列长度&a…...
xilinx fpga中pll与mmcm的区别
Xilinx中的PLL(锁相环)和MMCM(混合模式时钟管理器)都是用于时钟管理的关键组件,但它们之间存在一些显著的区别。以下是对两者的详细比较: 1. 功能特性 PLL(锁相环): 主…...
Python语法系列博客 · 第8期[特殊字符] Lambda函数与高阶函数:函数式编程初体验
上一期小练习解答(第7期回顾) ✅ 练习1:找出1~100中能被3或5整除的数 result [x for x in range(1, 101) if x % 3 0 or x % 5 0]✅ 练习2:生成字符串长度字典 words ["apple", "banana", "grape…...
黑马商城(五)微服务保护和分布式事务
一、雪崩问题 二、雪崩-解决方案(服务保护方案) 请求限流: 线程隔离: 服务熔断: 服务保护组件: 三、Sentinel 引入依赖: <!--sentinel--> <dependency><groupId>com.aliba…...
Java 编译与反编译深度解析
Java 编译与反编译深度解析 1. 编译过程详解 (1) 完整编译流程 .java 文件 → 词法分析 → 语法分析 → 语义分析 → 字节码生成 → .class 文件│ │ │ │↓ ↓ ↓ ↓识别关键字 生成抽象语法树 类型…...