Springboot整合Mybaits启动过程

news2024/10/2 3:27:05

Springboot整合Mybaits启动过程

  • 1.前言
  • 2.MybatisAutoConfiguration
  • 3.SqlSessionFactoryBean
    • 3.1 XMLConfigBuilder.parse()
      • 3.1.1 XMLMapperBuilder.parse()
        • 3.1.1.1 XMLStatementBuilder.parse()
  • 4.SqlSession
    • 4.1 Executor

1.前言

直接加载mybatis配置文件,然后创建SqlSessionFactory ,获取SqlSession来进行数据库操作

//加载配置文件
InputStream resourceAsStream = Resources.getResourceAsStream("ybatis-config.xml");
//创建sqlSessionFactory
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
//通过sqlsessionfactory得到sqlsession(sqlsession是操作数据库的关键对象)
SqlSession sqlSession = sqlSessionFactory.openSession();
}

而当Springboot整合Mybatis 时,这个 SqlSessionFactory 对象应该交由 Spring 容器来管理。
Spirngboot自动装配:Spirngboot自动装配

2.MybatisAutoConfiguration

我们知道springboot开箱即用,就是因为它能够自动装配,而自动装配的原理,就时会从META-INFO下的spring.factories文件中获取要自动装配的类。
在这里插入图片描述
进入MybatisAutoConfiguration类中

@org.springframework.context.annotation.Configuration
@ConditionalOnClass({ SqlSessionFactory.class, SqlSessionFactoryBean.class })
@ConditionalOnBean(DataSource.class)
@EnableConfigurationProperties(MybatisProperties.class)
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class MybatisAutoConfiguration {

	......
	@Bean
	@ConditionalOnMissingBean
	public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
	// 创建SqlSessionFactoryBean对象
	SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
	// 设置数据源
	factory.setDataSource(dataSource);
	// 设置VFS为SpringBootVFS
	factory.setVfs(SpringBootVFS.class);
	
	if (StringUtils.hasText(this.properties.getConfigLocation())) {
		// 如果配置了配置文件路径,则设置ConfigLocation
		factory.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
	}
	
	Configuration configuration = this.properties.getConfiguration();
	if (configuration == null && !StringUtils.hasText(this.properties.getConfigLocation())) {
		// 如果未配置配置文件路径且没有指定配置对象,则创建一个新的Configuration对象
		configuration = new Configuration();
	}
	
	if (configuration != null && !CollectionUtils.isEmpty(this.configurationCustomizers)) {
		// 如果存在配置对象且有配置自定义器,则依次调用自定义器的customize()方法对配置对象进行自定义
		for (ConfigurationCustomizer customizer : this.configurationCustomizers) {
			customizer.customize(configuration);
		}
	}
	
	// 设置配置对象
	factory.setConfiguration(configuration);
	
	if (this.properties.getConfigurationProperties() != null) {
		// 如果配置了额外的配置属性,则设置到SqlSessionFactoryBean中
		factory.setConfigurationProperties(this.properties.getConfigurationProperties());
	}
	
	if (!ObjectUtils.isEmpty(this.interceptors)) {
		// 如果存在拦截器,则设置到SqlSessionFactoryBean中
		factory.setPlugins(this.interceptors);
	}
	
	if (this.databaseIdProvider != null) {
		// 如果存在数据库ID提供者,则设置到SqlSessionFactoryBean中
		factory.setDatabaseIdProvider(this.databaseIdProvider);
	}
	
	if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
		// 如果配置了类型别名包路径,则设置到SqlSessionFactoryBean中
		factory.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
	}
	
	if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
		// 如果配置了类型处理器包路径,则设置到SqlSessionFactoryBean中
		factory.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
	}
	
	if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
		// 如果存在Mapper文件路径,则解析并设置到SqlSessionFactoryBean中
		factory.setMapperLocations(this.properties.resolveMapperLocations());
	}
	
	// 返回创建的SqlSessionFactory对象
	return factory.getObject();
	}
	......
}
@org.springframework.context.annotation.Configuration: 
这个注解表示这个类是一个配置类,Spring会在启动时加载并解析它。

@ConditionalOnClass({ SqlSessionFactory.class, SqlSessionFactoryBean.class }): 
这个注解表示只有在类路径中存在SqlSessionFactorySqlSessionFactoryBean类时才会进行自动配置。

@ConditionalOnBean(DataSource.class): 
这个注解表示只有当容器中已经存在DataSource类型的Bean时才会进行自动配置。

@EnableConfigurationProperties(MybatisProperties.class): 
这个注解启用了MybatisProperties类的配置。它会将该类的属性值绑定到MybatisAutoConfiguration类中。

@AutoConfigureAfter(DataSourceAutoConfiguration.class): 
这个注解表示该自动配置类需要在DataSourceAutoConfiguration类之后进行自动配置。

从上面代码可以知道,SqlSessionFactory Bean在这里被创建和配置,交给spring容器管理,SqlSessionFactory又是怎么创建的呢?我们来看SqlSessionFactoryBean

3.SqlSessionFactoryBean

我们可以看到SqlSessionFactoryBean实现了InitializingBean接口,覆写了afterPropertiesSet方法

public class SqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
	......
	@Override
  public void afterPropertiesSet() throws Exception {
    notNull(dataSource, "Property 'dataSource' is required");
    notNull(sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required");
    state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null),
              "Property 'configuration' and 'configLocation' can not specified with together");

	// 这里使用了建造者模式进行SqlSessionFactory的创建
    this.sqlSessionFactory = buildSqlSessionFactory();
  }

	protected SqlSessionFactory buildSqlSessionFactory() throws IOException {

    Configuration configuration;

    XMLConfigBuilder xmlConfigBuilder = null;
    if (this.configuration != null) {
      configuration = this.configuration;
      if (configuration.getVariables() == null) {
        configuration.setVariables(this.configurationProperties);
      } else if (this.configurationProperties != null) {
        configuration.getVariables().putAll(this.configurationProperties);
      }
    } else if (this.configLocation != null) {
      // 构建XmlConfigBuilder,准备解析XML文件的基础环境
      xmlConfigBuilder = new XMLConfigBuilder(this.configLocation.getInputStream(), null, this.configurationProperties);
      configuration = xmlConfigBuilder.getConfiguration();
    } else {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Property 'configuration' or 'configLocation' not specified, using default MyBatis Configuration");
      }
      configuration = new Configuration();
      if (this.configurationProperties != null) {
        configuration.setVariables(this.configurationProperties);
      }
    }

    if (this.objectFactory != null) {
      configuration.setObjectFactory(this.objectFactory);
    }

    if (this.objectWrapperFactory != null) {
      configuration.setObjectWrapperFactory(this.objectWrapperFactory);
    }

    if (this.vfs != null) {
      configuration.setVfsImpl(this.vfs);
    }

    if (hasLength(this.typeAliasesPackage)) {
      String[] typeAliasPackageArray = tokenizeToStringArray(this.typeAliasesPackage,
          ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
      for (String packageToScan : typeAliasPackageArray) {
        configuration.getTypeAliasRegistry().registerAliases(packageToScan,
                typeAliasesSuperType == null ? Object.class : typeAliasesSuperType);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Scanned package: '" + packageToScan + "' for aliases");
        }
      }
    }

    if (!isEmpty(this.typeAliases)) {
      for (Class<?> typeAlias : this.typeAliases) {
        configuration.getTypeAliasRegistry().registerAlias(typeAlias);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Registered type alias: '" + typeAlias + "'");
        }
      }
    }

    if (!isEmpty(this.plugins)) {
      for (Interceptor plugin : this.plugins) {
        configuration.addInterceptor(plugin);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Registered plugin: '" + plugin + "'");
        }
      }
    }

    if (hasLength(this.typeHandlersPackage)) {
      String[] typeHandlersPackageArray = tokenizeToStringArray(this.typeHandlersPackage,
          ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
      for (String packageToScan : typeHandlersPackageArray) {
        configuration.getTypeHandlerRegistry().register(packageToScan);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Scanned package: '" + packageToScan + "' for type handlers");
        }
      }
    }

    if (!isEmpty(this.typeHandlers)) {
      for (TypeHandler<?> typeHandler : this.typeHandlers) {
        configuration.getTypeHandlerRegistry().register(typeHandler);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Registered type handler: '" + typeHandler + "'");
        }
      }
    }

    if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
      try {
        configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
      } catch (SQLException e) {
        throw new NestedIOException("Failed getting a databaseId", e);
      }
    }

    if (this.cache != null) {
      configuration.addCache(this.cache);
    }

    if (xmlConfigBuilder != null) {
      try {
        // xml文件解析
        xmlConfigBuilder.parse();

        if (LOGGER.isDebugEnabled()) {
          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();
      }
    }

    if (this.transactionFactory == null) {
      this.transactionFactory = new SpringManagedTransactionFactory();
    }

    configuration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource));

    if (!isEmpty(this.mapperLocations)) {
      for (Resource mapperLocation : this.mapperLocations) {
        if (mapperLocation == null) {
          continue;
        }

        try {
          XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
              configuration, mapperLocation.toString(), configuration.getSqlFragments());
          xmlMapperBuilder.parse();
        } catch (Exception e) {
          throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
        } finally {
          ErrorContext.instance().reset();
        }

        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Parsed mapper file: '" + mapperLocation + "'");
        }
      }
    } else {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Property 'mapperLocations' was not specified or no matching resources found");
      }
    }
	// 构建SqlSessionFactory,返回的是DefaultSqlSessionFactory
    return this.sqlSessionFactoryBuilder.build(configuration);
  }
	......
}

从上面代码可以知道经过一系列操作最后通过sqlSessionFactoryBuilder创建了SqlSessionFactory。下面来看一下XML文件的解析

3.1 XMLConfigBuilder.parse()

public Configuration parse() {
    if (parsed) {
      throw new BuilderException("Each XMLConfigBuilder can only be used once.");
    }
    parsed = true;
    // xml配置文件转化成Configuration
    parseConfiguration(parser.evalNode("/configuration"));
    return configuration;
  }
  private void parseConfiguration(XNode root) {
    try {
      // 该方法中,将<configuration>下的所有节点分开处理
      propertiesElement(root.evalNode("properties"));
      Properties settings = settingsAsProperties(root.evalNode("settings"));
      loadCustomVfs(settings);
      loadCustomLogImpl(settings);
      typeAliasesElement(root.evalNode("typeAliases"));
      pluginElement(root.evalNode("plugins"));
      objectFactoryElement(root.evalNode("objectFactory"));
      objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
      reflectorFactoryElement(root.evalNode("reflectorFactory"));
      settingsElement(settings);
      environmentsElement(root.evalNode("environments"));
      databaseIdProviderElement(root.evalNode("databaseIdProvider"));
      typeHandlerElement(root.evalNode("typeHandlers"));
      // 解析映射文件,并将相关信息保存到Configuration对象中
      mapperElement(root.evalNode("mappers"));
    } catch (Exception e) {
      throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);
    }
  }
private void mapperElement(XNode parent) throws Exception {
    if (parent != null) {
      for (XNode child : parent.getChildren()) {
        if ("package".equals(child.getName())) {
          String mapperPackage = child.getStringAttribute("name");
          configuration.addMappers(mapperPackage);
        } else {
          String resource = child.getStringAttribute("resource");
          String url = child.getStringAttribute("url");
          String mapperClass = child.getStringAttribute("class");
          if (resource != null && url == null && mapperClass == null) {
            ErrorContext.instance().resource(resource);
            InputStream inputStream = Resources.getResourceAsStream(resource);
            // 创建XMLMapperBuilder
            XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
            // mapper文件解析
            mapperParser.parse();
          } else if (resource == null && url != null && mapperClass == null) {
            ErrorContext.instance().resource(url);
            InputStream inputStream = Resources.getUrlAsStream(url);
            XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url, configuration.getSqlFragments());
            mapperParser.parse();
          } else if (resource == null && url == null && mapperClass != null) {
            Class<?> mapperInterface = Resources.classForName(mapperClass);
            configuration.addMapper(mapperInterface);
          } else {
            throw new BuilderException("A mapper element may only specify a url, resource or class, but not more than one.");
          }
        }
      }
    }
  }

3.1.1 XMLMapperBuilder.parse()

public void parse() {
    if (!configuration.isResourceLoaded(resource)) {
      configurationElement(parser.evalNode("/mapper"));
      configuration.addLoadedResource(resource);
      bindMapperForNamespace();
    }

    parsePendingResultMaps();
    parsePendingCacheRefs();
    parsePendingStatements();
  }

  private void configurationElement(XNode context) {
    try {
      String namespace = context.getStringAttribute("namespace");
      if (namespace == null || namespace.equals("")) {
        throw new BuilderException("Mapper's namespace cannot be empty");
      }
      builderAssistant.setCurrentNamespace(namespace);
      cacheRefElement(context.evalNode("cache-ref"));
      cacheElement(context.evalNode("cache"));
      parameterMapElement(context.evalNodes("/mapper/parameterMap"));
      resultMapElements(context.evalNodes("/mapper/resultMap"));
      sqlElement(context.evalNodes("/mapper/sql"));
      buildStatementFromContext(context.evalNodes("select|insert|update|delete"));
    } catch (Exception e) {
      throw new BuilderException("Error parsing Mapper XML. The XML location is '" + resource + "'. Cause: " + e, e);
    }
  }
private void buildStatementFromContext(List<XNode> list) {
    if (configuration.getDatabaseId() != null) {
      buildStatementFromContext(list, configuration.getDatabaseId());
    }
    buildStatementFromContext(list, null);
  }

  private void buildStatementFromContext(List<XNode> list, String requiredDatabaseId) {
    for (XNode context : list) {
      final XMLStatementBuilder statementParser = new XMLStatementBuilder(configuration, builderAssistant, context, requiredDatabaseId);
      try {
        statementParser.parseStatementNode();
      } catch (IncompleteElementException e) {
        configuration.addIncompleteStatement(statementParser);
      }
    }
  }
3.1.1.1 XMLStatementBuilder.parse()
public void parseStatementNode() {
    String id = context.getStringAttribute("id");
    String databaseId = context.getStringAttribute("databaseId");

    if (!databaseIdMatchesCurrent(id, databaseId, this.requiredDatabaseId)) {
      return;
    }

    String nodeName = context.getNode().getNodeName();
    SqlCommandType sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase(Locale.ENGLISH));
    boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
    boolean flushCache = context.getBooleanAttribute("flushCache", !isSelect);
    boolean useCache = context.getBooleanAttribute("useCache", isSelect);
    boolean resultOrdered = context.getBooleanAttribute("resultOrdered", false);

    XMLIncludeTransformer includeParser = new XMLIncludeTransformer(configuration, builderAssistant);
    includeParser.applyIncludes(context.getNode());

    String parameterType = context.getStringAttribute("parameterType");
    Class<?> parameterTypeClass = resolveClass(parameterType);

    String lang = context.getStringAttribute("lang");
    LanguageDriver langDriver = getLanguageDriver(lang);

    // Parse selectKey after includes and remove them.
    processSelectKeyNodes(id, parameterTypeClass, langDriver);

    // Parse the SQL (pre: <selectKey> and <include> were parsed and removed)
    KeyGenerator keyGenerator;
    String keyStatementId = id + SelectKeyGenerator.SELECT_KEY_SUFFIX;
    keyStatementId = builderAssistant.applyCurrentNamespace(keyStatementId, true);
    if (configuration.hasKeyGenerator(keyStatementId)) {
      keyGenerator = configuration.getKeyGenerator(keyStatementId);
    } else {
      keyGenerator = context.getBooleanAttribute("useGeneratedKeys",
          configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType))
          ? Jdbc3KeyGenerator.INSTANCE : NoKeyGenerator.INSTANCE;
    }

    SqlSource sqlSource = langDriver.createSqlSource(configuration, context, parameterTypeClass);
    StatementType statementType = StatementType.valueOf(context.getStringAttribute("statementType", StatementType.PREPARED.toString()));
    Integer fetchSize = context.getIntAttribute("fetchSize");
    Integer timeout = context.getIntAttribute("timeout");
    String parameterMap = context.getStringAttribute("parameterMap");
    String resultType = context.getStringAttribute("resultType");
    Class<?> resultTypeClass = resolveClass(resultType);
    String resultMap = context.getStringAttribute("resultMap");
    String resultSetType = context.getStringAttribute("resultSetType");
    ResultSetType resultSetTypeEnum = resolveResultSetType(resultSetType);
    String keyProperty = context.getStringAttribute("keyProperty");
    String keyColumn = context.getStringAttribute("keyColumn");
    String resultSets = context.getStringAttribute("resultSets");

    builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
        fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,
        resultSetTypeEnum, flushCache, useCache, resultOrdered,
        keyGenerator, keyProperty, keyColumn, databaseId, langDriver, resultSets);
  }

到这里我们可以看到整个解析过程是对xml文件使用相应的xmlBuilder的parse()方法层层解析

4.SqlSession

在这里插入图片描述
构建好SqlSessionFactory后,就能获取到SqlSession。我们知道通过sqlSessionFactoryBuilder创建了SqlSessionFactory,并且返回的是实现了SqlSessionFactory的DefaultSqlSessionFactory,通过openSession()方法则可以获取SqlSession

public interface SqlSessionFactory {

  SqlSession openSession();

  SqlSession openSession(boolean autoCommit);

  SqlSession openSession(Connection connection);

  SqlSession openSession(TransactionIsolationLevel level);

  SqlSession openSession(ExecutorType execType);

  SqlSession openSession(ExecutorType execType, boolean autoCommit);

  SqlSession openSession(ExecutorType execType, TransactionIsolationLevel level);

  SqlSession openSession(ExecutorType execType, Connection connection);

  Configuration getConfiguration();

}
@Override
  public SqlSession openSession() {
    return openSessionFromDataSource(configuration.getDefaultExecutorType(), null, false);
  }
  
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
    Transaction tx = null;
    try {
      final Environment environment = configuration.getEnvironment();
      final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
      tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
      // 创建执行器
      final Executor executor = configuration.newExecutor(tx, execType);
      // 这里返回的是实现了SqlSeesion的DefaultSqlSession
      return new DefaultSqlSession(configuration, executor, autoCommit);
    } catch (Exception e) {
      closeTransaction(tx); // may have fetched a connection so lets call close()
      throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
    } finally {
      ErrorContext.instance().reset();
    }
  }

在这里插入图片描述

public DefaultSqlSession(Configuration configuration, Executor executor, boolean autoCommit) {
    this.configuration = configuration;
    this.executor = executor;
    this.dirty = false;
    this.autoCommit = autoCommit;
  }

在DefaultSqlSession我们可以看到很多我们熟悉的对数据库操作的方法
在这里插入图片描述

4.1 Executor

默认执行器:SimpleExecutor

public Executor newExecutor(Transaction transaction, ExecutorType executorType) {
    executorType = executorType == null ? defaultExecutorType : executorType;
    executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
    Executor executor;
    if (ExecutorType.BATCH == executorType) {
      executor = new BatchExecutor(this, transaction);
    } else if (ExecutorType.REUSE == executorType) {
      executor = new ReuseExecutor(this, transaction);
    } else {
      executor = new SimpleExecutor(this, transaction);
    }
    if (cacheEnabled) {
      executor = new CachingExecutor(executor);
    }
    executor = (Executor) interceptorChain.pluginAll(executor);
    return executor;
  }

从代码中可以看到根据不同的执行器类型创建相应的执行器。
(1)SimpleExecutor:每执行一次update或select,就开启一个Statement对象,用完立刻关闭Statement对象。
(2)ReuseExecutor:执行update或select,以sql作为key查找Statement对象,存在就使用,不存在就创建,用完后,不关闭Statement对象,而是放置于Map内,供下一次使用。简言之,就是重复使用Statement对象。
(3)BatchExecutor:执行update(没有select,JDBC批处理不支持select),将所有sql都添加到批处理中(addBatch()),等待统一执行(executeBatch()),它缓存了多个Statement对象,每个Statement对象都是addBatch()完毕后,等待逐一执行executeBatch()批处理。与JDBC批处理相同。
(4)CachingExecutor:CachingExecutor是一个Executor接口的装饰器,它为Executor对象增加了二级缓存的相关功能,委托的执行器对象可以是SimpleExecutor、ReuseExecutor、BatchExecutor中任一一个。执行 update 方法前判断是否清空二级缓存;执行 query 方法前先在二级缓存中查询,命中失败再通过被代理类查询。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1505419.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ssm爱心捐赠物资维护系统-计算机毕业设计源码09536

摘要 随着信息技术的快速发展&#xff0c;计算机应用已经进入成千上万的家庭。随着物资数量的增加&#xff0c;物资库存管理也存在许多问题。物资数据的处理量正在迅速增加&#xff0c;原来的手工管理模式不适合这种形式。使用计算机可以完成数据收集、处理和分析&#xff0c;减…

React useMemo钩子指南:优化计算性能

&#x1f90d; 前端开发工程师、技术日更博主、已过CET6 &#x1f368; 阿珊和她的猫_CSDN博客专家、23年度博客之星前端领域TOP1 &#x1f560; 牛客高级专题作者、打造专栏《前端面试必备》 、《2024面试高频手撕题》 &#x1f35a; 蓝桥云课签约作者、上架课程《Vue.js 和 E…

部署到 Adreno™ GPU

介绍​ Adreno™ 是由高通开发并用于许多 SoC 的图形处理单元&#xff08;GPU&#xff09;半导体 IP 核系列。 Adreno™ GPU 可以加速复杂几何图形的渲染&#xff0c;在提供高性能图形和丰富的用户体验的同时拥有很低的功耗。 TVM 使用 TVM 的原生 OpenCL 后端 和 OpenCLML …

【逆向实战 某视频防盗链参数的生成】防盗链cKey的生成,还要补环境?还是单嵌套的webpack?

逆向日期&#xff1a;2024.03.10 使用工具&#xff1a;Node.js 类型&#xff1a;单嵌套Webpack 文章全程已做去敏处理&#xff01;&#xff01;&#xff01; 【需要做的可联系我】 AES解密处理&#xff08;直接解密即可&#xff09;&#xff08;crypto-js.js 标准算法&#xf…

数据结构详解①——诸论

目录 前言 引入&#xff1a; 基本概念和术语 数据 数据元素 数据项 数据对象 数据结构 逻辑结构 物理结构 数据类型 为什么要设计出来数据类型呢&#xff1f; 数据类型的分类 抽象数据类型 数据结构与算法的关系 算法 定义 特性 设计要求 效率度量方法 事…

深入理解Java的Writer类

咦咦咦&#xff0c;各位小可爱&#xff0c;我是你们的好伙伴——bug菌&#xff0c;今天又来给大家普及Java SE相关知识点了&#xff0c;别躲起来啊&#xff0c;听我讲干货还不快点赞&#xff0c;赞多了我就有动力讲得更嗨啦&#xff01;所以呀&#xff0c;养成先点赞后阅读的好…

Python 初步了解urllib库:网络请求的利器

目录 urllib库简介 request模块 parse模块 error模块 response模块 读取响应内容 获取响应状态码 获取响应头部信息 处理重定向 关闭响应 总结 在Python的众多库中&#xff0c;urllib库是一个专门用于处理网络请求的强大工具。urllib库提供了多种方法来打开和读取UR…

【Django开发】0到1美多商城项目md教程第1篇:欢迎来到美多商城!【附代码文档】

本系列文章md笔记&#xff08;已分享&#xff09;主要讨论django商城项目相关知识。项目利用Django框架开发一套前后端不分离的商城项目&#xff08;4.0版本&#xff09;含代码和文档。功能包括前后端不分离&#xff0c;方便SEO。采用Django Jinja2模板引擎 Vue.js实现前后端…

递归类C++

1、汉诺塔 面试题 08.06. 汉诺塔问题 - 力扣(LeetCode) Why?为什么这个汉诺塔问题可以用递归来解决? 如何来解决汉诺塔问题? 如果N == 1时,A[0] B C,直接将A上的盘子转移到C上面。 如果N == 2时,A[1,0] B C,先将上面所有的盘子放到B,然后将A上最大的那个放到C,再把…

【前端CSS】CSS的3种基本选择器和5种高级选择器使用方式

目录 前言 基本选择器 1.1 标签选择器 1.2 ID选择器 1.3 类选择器 高级选择器 2.1 并集选择器 2.2 交集选择器 2.3 后代选择器 2.4 子元素选择器 2.5 属性选择器 前言 1W&#xff1a;什么是CSS选择器&#xff1f; CSS选择器由HTML元素的id、class属性或元素名本身以及…

1688平台官方开发平台API接口接入|发布商品|订单查询|跨境API接口

《财经十一人》获悉&#xff0c;阿里巴巴&#xff08;BABA.N&#xff09;旗下中国B2B平台1688正布局跨境业务。 举措主要有二&#xff1a;一是提供跨境版API接口&#xff0c;可将1688的货盘导入各类有流量的平台&#xff0c;比如各国代采网站、服务商SaaS&#xff08;软件服务…

pytorch的理解

工具的查看与使用帮助 1. dir import torch torch.cuda.is_available()dir(torch) dir(torch.cuda) #可以看到有"is_available" 2. help help(torch.cuda.is_available)

安装torch以及版本对应问题

首先查看cuda版本&#xff1a;winR 输入&#xff1a;nvidia -smi 我的cuda版本12.2&#xff0c;安装的torch版本要小于12.2 我的pip/conda源都改成清华源了&#xff0c;torch2.0以上的版本截止到2024年3月10日也没有。 pytorch官网&#xff1a;https://pytorch.org/ 寻找匹配…

jvm题库详解

1、JVM内存模型 注意&#xff1a;这个是基于jdk1.8之前的虚拟机&#xff0c;在jdk1.8后 已经没有方法区&#xff0c;一并合并到堆中的元空间了 JVM内存区域总共分为两种类型 线程私有区域&#xff1a;程序计数器、本地方法栈和虚拟机栈 线程共享区域&#xff1a;堆&#xff08…

2.16CACHE,页式存储器,虚拟~,CPU

CACHE SRAM比DRAM集成度低 下面的情况就是说同时找&#xff0c;所以就不用再从头找 映射方式 替换算法 就相当于插入排序调牌堆&#xff0c;如果被选中了&#xff0c;就放到牌堆第一个位置&#xff0c;那么其后面的所有排序相当于都1&#xff0c;不用考虑会超过后面的牌序&…

【Python】进阶学习:OpenCV--一文详解cv2.namedWindow()

【Python】进阶学习&#xff1a;OpenCV–一文详解cv2.namedWindow() &#x1f308; 个人主页&#xff1a;高斯小哥 &#x1f525; 高质量专栏&#xff1a;Matplotlib之旅&#xff1a;零基础精通数据可视化、Python基础【高质量合集】、PyTorch零基础入门教程&#x1f448; 希望…

SpringMVC08、Json

8、Json 8.1、什么是JSON&#xff1f; JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式&#xff0c;目前使用特别广泛。采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。易于人阅读和…

基于PCtoLCD实现OLED汉字取模方法

0 工具准备 PCtoLCD2002 NodeMCU&#xff08;ESP8266&#xff09;&#xff08;验证OLED字模效果&#xff09; 0.96寸OLED显示屏 1 基于PCtoLCD实现OLED汉字取模方法 1.1 基础知识介绍 0.96存OLED显示屏包含128x64个像素点&#xff0c;x轴方向为128个像素点&#xff0c;y轴方向…

Python 浅复制与深复制(Shallow Copy Deep Copy)

在Python中&#xff0c;赋值语句的意义是在对象与变量之间建立引用关系&#xff0c;相当于给对象起了名字。对于复合类型对象&#xff0c;由于其可以保存其他类型对象的引用&#xff0c;而在复制时即引出了“仅复制引用关系”或“同时复制引用对象”两种选择&#xff0c;即浅复…