【源码解析】Spring事务 @Transactional 源码解析

news2024/11/15 19:29:49

源码解析

自动化配置

spring-boot-autoconfigure查看spring.factories引入TransactionAutoConfiguration

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\

查看TransactionAutoConfiguration源码发现包含注解@EnableTransactionManagement

    @Configuration(
        proxyBeanMethods = false
    )
    @ConditionalOnBean({TransactionManager.class})
    @ConditionalOnMissingBean({AbstractTransactionManagementConfiguration.class})
    public static class EnableTransactionManagementConfiguration {
        public EnableTransactionManagementConfiguration() {
        }

        @Configuration(
            proxyBeanMethods = false
        )
        @EnableTransactionManagement(
            proxyTargetClass = true
        )
        @ConditionalOnProperty(
            prefix = "spring.aop",
            name = {"proxy-target-class"},
            havingValue = "true",
            matchIfMissing = true
        )
        public static class CglibAutoProxyConfiguration {
            public CglibAutoProxyConfiguration() {
            }
        }

        @Configuration(
            proxyBeanMethods = false
        )
        @EnableTransactionManagement(
            proxyTargetClass = false
        )
        @ConditionalOnProperty(
            prefix = "spring.aop",
            name = {"proxy-target-class"},
            havingValue = "false",
            matchIfMissing = false
        )
        public static class JdkDynamicAutoProxyConfiguration {
            public JdkDynamicAutoProxyConfiguration() {
            }
        }
    }

查看@EnableTransactionManagement源码,发现TransactionManagementConfigurationSelector

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({TransactionManagementConfigurationSelector.class})
public @interface EnableTransactionManagement {
    boolean proxyTargetClass() default false;

    AdviceMode mode() default AdviceMode.PROXY;

    int order() default 2147483647;
}

查看TransactionManagementConfigurationSelector,引入了ProxyTransactionManagementConfiguration

public class TransactionManagementConfigurationSelector extends AdviceModeImportSelector<EnableTransactionManagement> {
    public TransactionManagementConfigurationSelector() {
    }

    protected String[] selectImports(AdviceMode adviceMode) {
        switch(adviceMode) {
        case PROXY:
            return new String[]{AutoProxyRegistrar.class.getName(), ProxyTransactionManagementConfiguration.class.getName()};
        case ASPECTJ:
            return new String[]{this.determineTransactionAspectClass()};
        default:
            return null;
        }
    }

    private String determineTransactionAspectClass() {
        return ClassUtils.isPresent("javax.transaction.Transactional", this.getClass().getClassLoader()) ? "org.springframework.transaction.aspectj.AspectJJtaTransactionManagementConfiguration" : "org.springframework.transaction.aspectj.AspectJTransactionManagementConfiguration";
    }
}

切面和拦截器

ProxyTransactionManagementConfiguration往容器中注入BeanFactoryTransactionAttributeSourceAdvisor,切面是TransactionAttributeSource,拦截器是TransactionInterceptor

@Configuration(
    proxyBeanMethods = false
)
@Role(2)
public class ProxyTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration {
    public ProxyTransactionManagementConfiguration() {
    }

    @Bean(
        name = {"org.springframework.transaction.config.internalTransactionAdvisor"}
    )
    @Role(2)
    public BeanFactoryTransactionAttributeSourceAdvisor transactionAdvisor(TransactionAttributeSource transactionAttributeSource, TransactionInterceptor transactionInterceptor) {
        BeanFactoryTransactionAttributeSourceAdvisor advisor = new BeanFactoryTransactionAttributeSourceAdvisor();
        advisor.setTransactionAttributeSource(transactionAttributeSource);
        advisor.setAdvice(transactionInterceptor);
        if (this.enableTx != null) {
            advisor.setOrder((Integer)this.enableTx.getNumber("order"));
        }

        return advisor;
    }

    @Bean
    @Role(2)
    public TransactionAttributeSource transactionAttributeSource() {
        return new AnnotationTransactionAttributeSource();
    }

    @Bean
    @Role(2)
    public TransactionInterceptor transactionInterceptor(TransactionAttributeSource transactionAttributeSource) {
        TransactionInterceptor interceptor = new TransactionInterceptor();
        interceptor.setTransactionAttributeSource(transactionAttributeSource);
        if (this.txManager != null) {
            interceptor.setTransactionManager(this.txManager);
        }

        return interceptor;
    }
}

判断类是否需要被事务拦截。

AnnotationTransactionAttributeSource#isCandidateClass,判断是候选类

    public boolean isCandidateClass(Class<?> targetClass) {
        Iterator var2 = this.annotationParsers.iterator();

        TransactionAnnotationParser parser;
        do {
            if (!var2.hasNext()) {
                return false;
            }

            parser = (TransactionAnnotationParser)var2.next();
        } while(!parser.isCandidateClass(targetClass));

        return true;
    }

SpringTransactionAnnotationParser#isCandidateClass

    public boolean isCandidateClass(Class<?> targetClass) {
        return AnnotationUtils.isCandidateClass(targetClass, Transactional.class);
    }

拦截器的具体逻辑

拦截器TransactionInterceptor,执行TransactionInterceptor#invoke方法。

    @Nullable
    public Object invoke(MethodInvocation invocation) throws Throwable {
        Class<?> targetClass = invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null;
        Method var10001 = invocation.getMethod();
        invocation.getClass();
        return this.invokeWithinTransaction(var10001, targetClass, invocation::proceed);
    }

TransactionAspectSupport#invokeWithinTransaction,具体的事务处理逻辑。

  1. createTransactionIfNecessary。创建事务,包含数据库的连接和事务状态等信息;

  2. completeTransactionAfterThrowing。调用目标方法报错,回滚;

  3. commitTransactionAfterReturning。调用目标方法成功,提交事务(里面有一些判断,不符合条件可能会回滚)

    @Nullable
    protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targetClass, TransactionAspectSupport.InvocationCallback invocation) throws Throwable {
        TransactionAttributeSource tas = this.getTransactionAttributeSource();
        TransactionAttribute txAttr = tas != null ? tas.getTransactionAttribute(method, targetClass) : null;
        TransactionManager tm = this.determineTransactionManager(txAttr);
        if (this.reactiveAdapterRegistry != null && tm instanceof ReactiveTransactionManager) {
            // ... 
        } else {
            PlatformTransactionManager ptm = this.asPlatformTransactionManager(tm);
            String joinpointIdentification = this.methodIdentification(method, targetClass, txAttr);
            Object retVal;
            // ...
            } else {
                TransactionAspectSupport.TransactionInfo txInfo = this.createTransactionIfNecessary(ptm, txAttr, joinpointIdentification);

                try {
                    retVal = invocation.proceedWithInvocation();
                } catch (Throwable var18) {
                    this.completeTransactionAfterThrowing(txInfo, var18);
                    throw var18;
                } finally {
                    this.cleanupTransactionInfo(txInfo);
                }

                if (vavrPresent && TransactionAspectSupport.VavrDelegate.isVavrTry(retVal)) {
                    TransactionStatus status = txInfo.getTransactionStatus();
                    if (status != null && txAttr != null) {
                        retVal = TransactionAspectSupport.VavrDelegate.evaluateTryFailure(retVal, txAttr, status);
                    }
                }

                this.commitTransactionAfterReturning(txInfo);
                return retVal;
            }
        }
    }

获取事务

TransactionAspectSupport#createTransactionIfNecessary,创建事务

    protected TransactionAspectSupport.TransactionInfo createTransactionIfNecessary(@Nullable PlatformTransactionManager tm, @Nullable TransactionAttribute txAttr, final String joinpointIdentification) {
        if (txAttr != null && ((TransactionAttribute)txAttr).getName() == null) {
            txAttr = new DelegatingTransactionAttribute((TransactionAttribute)txAttr) {
                public String getName() {
                    return joinpointIdentification;
                }
            };
        }

        TransactionStatus status = null;
        if (txAttr != null) {
            if (tm != null) {
                status = tm.getTransaction((TransactionDefinition)txAttr);
            } else if (this.logger.isDebugEnabled()) {
                this.logger.debug("Skipping transactional joinpoint [" + joinpointIdentification + "] because no transaction manager has been configured");
            }
        }

        return this.prepareTransactionInfo(tm, (TransactionAttribute)txAttr, joinpointIdentification, status);
    }

AbstractPlatformTransactionManager#getTransaction,获取事务。

    public final TransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException {
        TransactionDefinition def = definition != null ? definition : TransactionDefinition.withDefaults();
        Object transaction = this.doGetTransaction();
        boolean debugEnabled = this.logger.isDebugEnabled();
        if (this.isExistingTransaction(transaction)) {
            return this.handleExistingTransaction(def, transaction, debugEnabled);
        } else if (def.getTimeout() < -1) {
            throw new InvalidTimeoutException("Invalid transaction timeout", def.getTimeout());
        } else if (def.getPropagationBehavior() == 2) {
            throw new IllegalTransactionStateException("No existing transaction found for transaction marked with propagation 'mandatory'");
        } else if (def.getPropagationBehavior() != 0 && def.getPropagationBehavior() != 3 && def.getPropagationBehavior() != 6) {
            if (def.getIsolationLevel() != -1 && this.logger.isWarnEnabled()) {
                this.logger.warn("Custom isolation level specified but no actual transaction initiated; isolation level will effectively be ignored: " + def);
            }

            boolean newSynchronization = this.getTransactionSynchronization() == 0;
            return this.prepareTransactionStatus(def, (Object)null, true, newSynchronization, debugEnabled, (Object)null);
        } else {
            AbstractPlatformTransactionManager.SuspendedResourcesHolder suspendedResources = this.suspend((Object)null);
            if (debugEnabled) {
                this.logger.debug("Creating new transaction with name [" + def.getName() + "]: " + def);
            }

            try {
                return this.startTransaction(def, transaction, debugEnabled, suspendedResources);
            } catch (Error | RuntimeException var7) {
                this.resume((Object)null, suspendedResources);
                throw var7;
            }
        }
    }

    private TransactionStatus startTransaction(TransactionDefinition definition, Object transaction, boolean debugEnabled, @Nullable AbstractPlatformTransactionManager.SuspendedResourcesHolder suspendedResources) {
        boolean newSynchronization = this.getTransactionSynchronization() != 2;
        DefaultTransactionStatus status = this.newTransactionStatus(definition, transaction, true, newSynchronization, debugEnabled, suspendedResources);
        this.doBegin(transaction, definition);
        this.prepareSynchronization(status, definition);
        return status;
    }

DataSourceTransactionManager#doBegin,事务管理器开启连接,设置未提交。判断事务是新的,则将资源绑定到TransactionSynchronizationManager

    protected void doBegin(Object transaction, TransactionDefinition definition) {
        DataSourceTransactionManager.DataSourceTransactionObject txObject = (DataSourceTransactionManager.DataSourceTransactionObject)transaction;
        Connection con = null;

        try {
            if (!txObject.hasConnectionHolder() || txObject.getConnectionHolder().isSynchronizedWithTransaction()) {
                Connection newCon = this.obtainDataSource().getConnection();
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("Acquired Connection [" + newCon + "] for JDBC transaction");
                }

                txObject.setConnectionHolder(new ConnectionHolder(newCon), true);
            }

            txObject.getConnectionHolder().setSynchronizedWithTransaction(true);
            con = txObject.getConnectionHolder().getConnection();
            Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
            txObject.setPreviousIsolationLevel(previousIsolationLevel);
            txObject.setReadOnly(definition.isReadOnly());
            if (con.getAutoCommit()) {
                txObject.setMustRestoreAutoCommit(true);
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("Switching JDBC Connection [" + con + "] to manual commit");
                }

                con.setAutoCommit(false);
            }

            this.prepareTransactionalConnection(con, definition);
            txObject.getConnectionHolder().setTransactionActive(true);
            int timeout = this.determineTimeout(definition);
            if (timeout != -1) {
                txObject.getConnectionHolder().setTimeoutInSeconds(timeout);
            }

            if (txObject.isNewConnectionHolder()) {
                TransactionSynchronizationManager.bindResource(this.obtainDataSource(), txObject.getConnectionHolder());
            }

        } catch (Throwable var7) {
            if (txObject.isNewConnectionHolder()) {
                DataSourceUtils.releaseConnection(con, this.obtainDataSource());
                txObject.setConnectionHolder((ConnectionHolder)null, false);
            }

            throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", var7);
        }
    }

事务的数据库连接信息将保存到TransactionSynchronizationManager

    private static final ThreadLocal<Map<Object, Object>> resources = new NamedThreadLocal("Transactional resources");
    
	public static void bindResource(Object key, Object value) throws IllegalStateException {
        Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
        Assert.notNull(value, "Value must not be null");
        Map<Object, Object> map = (Map)resources.get();
        if (map == null) {
            map = new HashMap();
            resources.set(map);
        }

        Object oldValue = ((Map)map).put(actualKey, value);
        if (oldValue instanceof ResourceHolder && ((ResourceHolder)oldValue).isVoid()) {
            oldValue = null;
        }

        if (oldValue != null) {
            throw new IllegalStateException("Already value [" + oldValue + "] for key [" + actualKey + "] bound to thread [" + Thread.currentThread().getName() + "]");
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace("Bound value [" + value + "] for key [" + actualKey + "] to thread [" + Thread.currentThread().getName() + "]");
            }

        }
    }

事务回滚

TransactionAspectSupport#completeTransactionAfterThrowing

    protected void completeTransactionAfterThrowing(@Nullable TransactionAspectSupport.TransactionInfo txInfo, Throwable ex) {
        if (txInfo != null && txInfo.getTransactionStatus() != null) {
            if (this.logger.isTraceEnabled()) {
                this.logger.trace("Completing transaction for [" + txInfo.getJoinpointIdentification() + "] after exception: " + ex);
            }

            if (txInfo.transactionAttribute != null && txInfo.transactionAttribute.rollbackOn(ex)) {
                try {
                    txInfo.getTransactionManager().rollback(txInfo.getTransactionStatus());
                } catch (TransactionSystemException var6) {
                    this.logger.error("Application exception overridden by rollback exception", ex);
                    var6.initApplicationException(ex);
                    throw var6;
                } catch (Error | RuntimeException var7) {
                    this.logger.error("Application exception overridden by rollback exception", ex);
                    throw var7;
                }
            } else {
                try {
                    txInfo.getTransactionManager().commit(txInfo.getTransactionStatus());
                } catch (TransactionSystemException var4) {
                    this.logger.error("Application exception overridden by commit exception", ex);
                    var4.initApplicationException(ex);
                    throw var4;
                } catch (Error | RuntimeException var5) {
                    this.logger.error("Application exception overridden by commit exception", ex);
                    throw var5;
                }
            }
        }

    }

AbstractPlatformTransactionManager#rollback

    public final void rollback(TransactionStatus status) throws TransactionException {
        if (status.isCompleted()) {
            throw new IllegalTransactionStateException("Transaction is already completed - do not call commit or rollback more than once per transaction");
        } else {
            DefaultTransactionStatus defStatus = (DefaultTransactionStatus)status;
            this.processRollback(defStatus, false);
        }
    }

DataSourceTransactionManager#doRollback,调用到Connection的回滚方法

    protected void doRollback(DefaultTransactionStatus status) {
        DataSourceTransactionManager.DataSourceTransactionObject txObject = (DataSourceTransactionManager.DataSourceTransactionObject)status.getTransaction();
        Connection con = txObject.getConnectionHolder().getConnection();
        if (status.isDebug()) {
            this.logger.debug("Rolling back JDBC transaction on Connection [" + con + "]");
        }

        try {
            con.rollback();
        } catch (SQLException var5) {
            throw new TransactionSystemException("Could not roll back JDBC transaction", var5);
        }
    }

事务提交

TransactionAspectSupport#commitTransactionAfterReturning,进行事务提交

    protected void commitTransactionAfterReturning(@Nullable TransactionAspectSupport.TransactionInfo txInfo) {
        if (txInfo != null && txInfo.getTransactionStatus() != null) {
            if (this.logger.isTraceEnabled()) {
                this.logger.trace("Completing transaction for [" + txInfo.getJoinpointIdentification() + "]");
            }

            txInfo.getTransactionManager().commit(txInfo.getTransactionStatus());
        }

    }

获取连接

SpringManagedTransaction#getConnection

    public Connection getConnection() throws SQLException {
        if (this.connection == null) {
            this.openConnection();
        }

        return this.connection;
    }

    private void openConnection() throws SQLException {
        this.connection = DataSourceUtils.getConnection(this.dataSource);
        this.autoCommit = this.connection.getAutoCommit();
        this.isConnectionTransactional = DataSourceUtils.isConnectionTransactional(this.connection, this.dataSource);
        LOGGER.debug(() -> {
            return "JDBC Connection [" + this.connection + "] will" + (this.isConnectionTransactional ? " " : " not ") + "be managed by Spring";
        });
    }

DataSourceUtils#getConnection,获取连接,是从TransactionSynchronizationManager获取的,用到了线程变量。

    public static Connection getConnection(DataSource dataSource) throws CannotGetJdbcConnectionException {
        try {
            return doGetConnection(dataSource);
        } catch (SQLException var2) {
            throw new CannotGetJdbcConnectionException("Failed to obtain JDBC Connection", var2);
        } catch (IllegalStateException var3) {
            throw new CannotGetJdbcConnectionException("Failed to obtain JDBC Connection: " + var3.getMessage());
        }
    }

    public static Connection doGetConnection(DataSource dataSource) throws SQLException {
        Assert.notNull(dataSource, "No DataSource specified");
        ConnectionHolder conHolder = (ConnectionHolder)TransactionSynchronizationManager.getResource(dataSource);
        if (conHolder == null || !conHolder.hasConnection() && !conHolder.isSynchronizedWithTransaction()) {
            logger.debug("Fetching JDBC Connection from DataSource");
            Connection con = fetchConnection(dataSource);
            if (TransactionSynchronizationManager.isSynchronizationActive()) {
                try {
                    ConnectionHolder holderToUse = conHolder;
                    if (conHolder == null) {
                        holderToUse = new ConnectionHolder(con);
                    } else {
                        conHolder.setConnection(con);
                    }

                    holderToUse.requested();
                    TransactionSynchronizationManager.registerSynchronization(new DataSourceUtils.ConnectionSynchronization(holderToUse, dataSource));
                    holderToUse.setSynchronizedWithTransaction(true);
                    if (holderToUse != conHolder) {
                        TransactionSynchronizationManager.bindResource(dataSource, holderToUse);
                    }
                } catch (RuntimeException var4) {
                    releaseConnection(con, dataSource);
                    throw var4;
                }
            }

            return con;
        } else {
            conHolder.requested();
            if (!conHolder.hasConnection()) {
                logger.debug("Fetching resumed JDBC Connection from DataSource");
                conHolder.setConnection(fetchConnection(dataSource));
            }

            return conHolder.getConnection();
        }
    }

在这里插入图片描述

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

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

相关文章

大数据之Spark运行流程

文章目录 前言&#xff08;一&#xff09;Spark On Yarn集群的Client模式运行流程&#xff08;二&#xff09; Spark On Yarn集群的Cluster模式运行流程总结 前言 #博学谷IT学习技术支持# 上篇文章有讨论到Spark On Yarn的两种部署模式&#xff0c;如果有不清楚的地方&#xf…

java ssm高校学术会议论文管理系统

在研究课题--学术会议论文管理系统的实现与设计&#xff0c;对操作使用的便利性&#xff0c;系统的可制定性和安全性以及管理的全面性等多个方面研究。其中主要研究的内容是将学术会议论文管理系统功能划分为: 通知类型、通知信息、部门信息、用户信息用户反馈、会议类型、会议…

JavaScript(JS)-1.JS入门

1.JavaScript概念 (1)JavaScript是一门跨平台&#xff0c;面向对象的脚本语言&#xff0c;来控制网页行为的&#xff0c;它能使网页可交互 (2)W3C标准&#xff1a;网页主要由三部分组成 ①结构&#xff1a;HTML负责网页的基本结构&#xff08;页面元素和内容&#xff09;。 …

4.6 曲线拟合的最小二乘法

4.6.1 最小二乘问题的提法 学习目标&#xff1a; 要学习曲线拟合的最小二乘法&#xff0c;我会按照以下步骤进行&#xff1a; 理解最小二乘法的基本思想和原理&#xff0c;即在已知数据的情况下&#xff0c;通过拟合一条曲线&#xff0c;使得曲线与数据之间的误差最小化。 …

科技创新催生新动能,“云游戏+”打通数字经济任督二脉

配图来自Canva可画 利好政策接连发布&#xff0c;人工智能、云计算等前沿技术席卷各行各业&#xff0c;传统行业网络化、数字化、智能化转型已不可逆&#xff0c;数字经济将迎来大爆发。 国务院发展研究中心市场经济研究所所长王微在中国发展高层论坛2023年年会上表示&#x…

< elementUi组件封装: 通过 el-tag、el-popover、vue动画等实现公告轮播 >

文章目录 &#x1f449; 前言&#x1f449; 一、效果演示&#x1f449; 二、实现思路&#x1f449; 三、实现案例往期内容 &#x1f4a8; &#x1f449; 前言 在 Vue elementUi 开发中&#xff0c;遇到这么一个需求&#xff0c;要实现公告轮播的效果。说实话&#xff0c;一开…

大家进来了解2023年6月CDGA/CDGP数据治理认证考试报名

DAMA认证为数据管理专业人士提供职业目标晋升规划&#xff0c;彰显了职业发展里程碑及发展阶梯定义&#xff0c;帮助数据管理从业人士获得企业数字化转型战略下的必备职业能力&#xff0c;促进开展工作实践应用及实际问题解决&#xff0c;形成企业所需的新数字经济下的核心职业…

多个微服务怎么放入一个tomcat

前言&#xff1a;相信看到这篇文章的小伙伴都或多或少有一些编程基础&#xff0c;懂得一些linux的基本命令了吧&#xff0c;本篇文章将带领大家服务器如何部署一个使用django框架开发的一个网站进行云服务器端的部署。 文章使用到的的工具 Python&#xff1a;一种编程语言&…

(一)Linux 环境下搭建 ElasticSearch (CentOS 7)

目录 1、搭建 Linux 相关环境 2、执行解压操作 3、创建新用户 4、修改配置文件 elasticsearch.yml 5、启动 ElasticSearch 6、修改虚拟机配置文件 7、重新启动 ElasticSearch 8、查看是否启动命令 9、访问 ElasticSearch 1、搭建 Linux 相关环境 没有服务器安装VM&a…

Golang每日一练(leetDay0043)

目录 127. 单词接龙 Word Ladder &#x1f31f;&#x1f31f;&#x1f31f; 128. 最长连续序列 Longest Consecutive Sequence &#x1f31f;&#x1f31f; 129. 求根节点到叶节点数字之和 Sum Root-to-leaf Numbers &#x1f31f;&#x1f31f; &#x1f31f; 每日一练…

QML控件和对话框之ApplicationWindows

ApplicationWindows ApplicationWindows应用程序窗口Action菜单类控件3.StatusBar4.工具栏控件类 ApplicationWindows应用程序窗口 Application Window在 Qt Quick Controls中类似于QMain Window 在 Qt/C中的角色&#xff0c;ApplicationWindow可以充当应用程序顶层窗口&#…

气传导耳机是什么原理?气传导蓝牙耳机优缺点分析

气传导耳机&#xff0c;简而言之&#xff0c;就是一种通过空气振动进行声音传播的耳机&#xff0c;采用波束成形技术进行定向传音&#xff0c;开放双耳设计模式&#xff0c;将音频传送到耳朵。 其发声途径&#xff0c;和我们双耳聆听到环境音以及人声的途径都是一样的&#xf…

UART协议——异步全双工串行通信方式

文章目录 前言一、简介1、优点2、缺点 二、数据格式三、波特率1、定义2、波特率和采样频率 四、常见接口电平1、TTL电平2、RS232&#xff08;负逻辑&#xff09;3、RS485 前言 2023.4.22 世界地球日 一、简介 UART&#xff1a;Universal Asynchronous Receiver/Transmitter&a…

数据驱动+AI引擎,为MarTech打开全新的想象空间

‍数据智能产业创新服务媒体 ——聚焦数智 改变商业 近年来&#xff0c;随着全球数字化、信息化进程不断提速&#xff0c;企业营销的战场也逐渐转移至线上。一方面&#xff0c;消费者行为的数字化使得企业营销活动更加依赖于线上数字营销&#xff1b;另一方面&#xff0c;包括…

Python3 字符串

Python3 字符串 字符串是 Python 中最常用的数据类型。我们可以使用引号( 或 " )来创建字符串。 创建字符串很简单&#xff0c;只要为变量分配一个值即可。例如&#xff1a; var1 Hello World! var2 "Runoob" Python 访问字符串中的值 Python 不支持单字符…

MySQL-CENTOS7下MySQL单实例安装

MySQL单实例安装 1 版本下载2 MySQL安装2.1 创建目录并解压2.2 安装数据库2.3 安装RPM包2.4 启动服务2.5 连接MYSQL 3 MYSQL卸载卸载4 FAQ 1 版本下载 mysql下载 选择对应的版本。我选择的是的8.0.31的版本。 2 MySQL安装 2.1 创建目录并解压 mkdir /mysql mkdir /mysql/s…

chatgpt智能提效职场办公-ppt怎么转pdf文件

作者&#xff1a;虚坏叔叔 博客&#xff1a;https://xuhss.com 早餐店不会开到晚上&#xff0c;想吃的人早就来了&#xff01;&#x1f604; 要将PPT转为PDF文件&#xff0c;可以按照以下步骤操作&#xff1a; 1.打开PPT文件&#xff0c;点击“文件”菜单&#xff0c;选择“导出…

浅析商场智能导购系统功能与实施效益

商场智能导购系统是一种基于物联网技术和人工智能算法的解决方案&#xff0c;旨在提供商场内部的智能导购服务&#xff0c;为消费者提供个性化的购物导引和推荐&#xff0c;提升用户购物体验&#xff0c;增加商场的客流量和销售额。 商场智能导购系统的方案一般包括以下主要功能…

react中前端同学如何模拟使用后端接口操作数据?

为什么前端同学需要模拟后端数据 作为一个前端&#xff0c;在实现项目功能的时候&#xff0c;需要在前端写一个静态的json数据&#xff0c;进行测试。 项目中后端的接口往往是较晚才会出来&#xff0c;并且还要写接口文档&#xff0c;于是我们的前端的许多开发都要等到接口给…

pytest中的钩子函数:pytest_addoption(parser)

# python3 # Time : 2023/4/21 9:05 # Author : Jike_Ma # FileName: conftest.pyimport pytesthosts {"dev": "http://dev.com.cn","prod": "http://prod.com.cn","test": "http://test.com.cn" }# 注册一个…