Spring管理数据库事务

news2024/9/21 14:38:50

Spring编程式事务和声明式事务的验证

  • 1、工程目录
    • pom.xml
  • 2、在resources目录创建配置文件
    • applicationContext_1.xml
    • applicationContext_2.xml
    • applicationContext_3.xml
    • jdbc.properties
  • 3、创建数据表account
    • account
  • 4、创建dao类
  • 5、创建service类
  • 6、创建测试类
  • 7、实验结果图
    • 1 编程式事务
    • 2 声明式事务

1、工程目录

在这里插入图片描述

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>chapter10</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>6</source>
                    <target>6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.7.4</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.0.8.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.27</version>
        </dependency>

        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5.5</version>
        </dependency>

        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>mchange-commons-java</artifactId>
            <version>0.2.19</version>
        </dependency>
    </dependencies>

</project>

2、在resources目录创建配置文件

applicationContext_1.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">
	<!-- 引入外部 properties 文件 -->
	<context:property-placeholder
		location="classpath:jdbc.properties" />
	<!-- 注册数据源 -->
	<bean name="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClass}" />
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
		<property name="user" value="${jdbc.user}" />
		<property name="password" value="${jdbc.password}" />
	</bean>
	<!--注册JdbcTemplate-->
	<bean name="jdbcTemplate"
		class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 注册事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 注册TransactionTemplate-->
	<bean id="transactionTemplate"
		class="org.springframework.transaction.support.TransactionTemplate">
		<property name="transactionManager" ref="transactionManager" />
	</bean>
	<bean name="accountDao" class="com.qfedu.dao.AccountDaoImpl">
		<property name="jdbcTemplate" ref="jdbcTemplate"></property>
	</bean>
	<bean name="accountService"
		class="com.qfedu.service.AccountServiceImpl01">
		<property name="accountDao" ref="accountDao"></property>
		<property name="transactionTemplate"
			ref="transactionTemplate"></property>
	</bean>

</beans>

applicationContext_2.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">
	<!-- 引入外部 properties 文件 -->
	<context:property-placeholder
		location="classpath:jdbc.properties" />
	<!-- 注册数据源 -->
	<bean name="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClass}" />
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
		<property name="user" value="${jdbc.user}" />
		<property name="password" value="${jdbc.password}" />
	</bean>
	<!-- 注册JdbcTemplate-->
	<bean name="jdbcTemplate"
		class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 注册事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<bean name="accountDao" class="com.qfedu.dao.AccountDaoImpl">
		<property name="jdbcTemplate" ref="jdbcTemplate" />
	</bean>
	<bean name="accountService"
		class="com.qfedu.service.AccountServiceImpl02">
		<property name="accountDao" ref="accountDao" />
	</bean>
	<!-- 事务通知 -->
	<tx:advice id="txAdvice"
		transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="transfer*" propagation="REQUIRED" />
		</tx:attributes>
	</tx:advice>
	<!-- AOP配置 -->
	<aop:config>
		<aop:pointcut id="txPointCut"
			expression="execution(* com..service..*.*(..))" />
		<aop:advisor advice-ref="txAdvice"
			pointcut-ref="txPointCut" />
	</aop:config>
</beans>

applicationContext_3.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd">
	<!-- 引入外部 properties 文件 -->
	<context:property-placeholder
		location="classpath:jdbc.properties" />
	<!-- 注册数据源 -->
	<bean name="dataSource"
		class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="${jdbc.driverClass}" />
		<property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
		<property name="user" value="${jdbc.user}" />
		<property name="password" value="${jdbc.password}" />
	</bean>
	<!-- 注册JdbcTemplate-->
	<bean name="jdbcTemplate"
		class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 注册事务管理器 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<bean name="accountDao" class="com.qfedu.dao.AccountDaoImpl">
		<property name="jdbcTemplate" ref="jdbcTemplate" />
	</bean>
	<bean name="accountService"
		class="com.qfedu.service.AccountServiceImpl03">
		<property name="accountDao" ref="accountDao" />
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

jdbc.properties

jdbc.driverClass=com.mysql.cj.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/chapter10
jdbc.user=root
jdbc.password=123456

3、创建数据表account

account

在这里插入图片描述

4、创建dao类

AccountDao

package com.qfedu.dao;

public interface AccountDao {
	void increaseMoney(Integer id, Double money);

	void decreaseMoney(Integer id, Double money);
}

AccountDaoImpl

package com.qfedu.dao;

import org.springframework.jdbc.core.JdbcTemplate;

public class AccountDaoImpl implements AccountDao {
	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	@Override
	public void increaseMoney(Integer id, Double money) {
		jdbcTemplate.update("update account set money = money + ? " + "where id = ? ;", money, id);
	}

	@Override
	public void decreaseMoney(Integer id, Double money) {
		jdbcTemplate.update("update account set money = money - ? " + "where id = ? ;", money, id);
	}
}

5、创建service类

AccountService

package com.qfedu.service;

public interface AccountService {
	void transfer(Integer from, Integer to, Double money);
}

注意

修改AccountServiceImpl

实现转账业务

accountDao.decreaseMoney(from, money);
accountDao.increaseMoney(to, money);

验证实现了事务

当出现异常时(此处异常为分母为0),事务回滚,转账操作不会被提交

accountDao.decreaseMoney(from, money);
int num = 1 / 0;
accountDao.increaseMoney(to, money);

①和②二者保存一个,使用其中一个时,注释掉另一个,三个实现类都是这样。

AccountServiceImpl01

package com.qfedu.service;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.*;
import com.qfedu.dao.AccountDao;

public class AccountServiceImpl01 implements AccountService {
	private AccountDao accountDao;
	// 事务管理类
	private TransactionTemplate transactionTemplate;

	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

	public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
		this.transactionTemplate = transactionTemplate;
	}
// final 声明方法,Java 里用 final 修饰符去修饰一个方法的唯一正确用途就是表达:
// 这个方法原本是一个虚方法,现在通过 final 来声明这个方法不允许在派生类中进一步被覆写(override)。
	@Override
	public void transfer(final Integer from, final Integer to, final Double money) {
		// 调用TransactionTemplate类对象执行execute()方法
		transactionTemplate.execute(new TransactionCallbackWithoutResult() {
			@Override
			// 需要在事务环境中执行的代码
			protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//				accountDao.decreaseMoney(from, money);
//				accountDao.increaseMoney(to, money);
				accountDao.decreaseMoney(from, money);
				int num = 1 / 0;
				accountDao.increaseMoney(to, money);

			}
		});
	}
}

AccountServiceImpl02

package com.qfedu.service;

import com.qfedu.dao.AccountDao;

public class AccountServiceImpl02 implements AccountService {
	private AccountDao accountDao;

	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

	@Override
	public void transfer(Integer from, Integer to, Double money) {
		accountDao.decreaseMoney(from, money);
		accountDao.increaseMoney(to, money);
//		accountDao.decreaseMoney(from,money);
//		int num = 1/0;
//		accountDao.increaseMoney(to,money);

	}
}

AccountServiceImpl03

package com.qfedu.service;

import org.springframework.transaction.annotation.Transactional;
import com.qfedu.dao.AccountDao;

@Transactional
public class AccountServiceImpl03 implements AccountService {
	private AccountDao accountDao;

	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

	@Override
	public void transfer(Integer from, Integer to, Double money) {
//		accountDao.decreaseMoney(from, money);
//		accountDao.increaseMoney(to, money);
		accountDao.decreaseMoney(from, money);
		int num = 1 / 0;
		accountDao.increaseMoney(to, money);

	}
}

6、创建测试类

TestAccountService01

package com.qfedu.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.qfedu.service.AccountService;

public class TestAccountService01 {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_1.xml");
		AccountService accountService = context.getBean("accountService", AccountService.class);
		accountService.transfer(1, 2, 1000.0);
	}
}

TestAccountService02

package com.qfedu.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.qfedu.service.AccountService;

public class TestAccountService02 {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_2.xml");
		AccountService accountService = context.getBean("accountService", AccountService.class);
		accountService.transfer(1, 2, 1000.0);
	}
}

TestAccountService03

package com.qfedu.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.qfedu.service.AccountService;

public class TestAccountService03 {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_3.xml");
		AccountService accountService = context.getBean("accountService", AccountService.class);
		accountService.transfer(1, 2, 1000.0);
	}
}

7、实验结果图

1 编程式事务

验证实现编程式事务
当程序出现异常时,事务回滚,操作不会被提交
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

2 声明式事务

验证实现声明式事务
当程序出现异常时,事务回滚,操作不会被提交
在这里插入图片描述

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

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

相关文章

基于python的点云处理库总结

想对于PCL&#xff0c;python处理点云的库还是比较多的&#xff0c;下面对此进行简单的总结&#xff1a; 一、Open3D A Modern Library for 3D Data Processing&#xff0c;Intel出品&#xff0c;MIT协议。 Open3D是一个支持3D数据处理软件快速开发的开源库。Open3D使用C和P…

CSS - 垂直菜单(鼠标移入时显示右侧容器)

效果图 示例源码 <body><section class="content"><ul class=

OpenVINO 2022.3之四:OpenVINO模型转换

OpenVINO 2022.3之四&#xff1a;OpenVINO模型转换 OpenVINO 2022.3 支持的模型格式: OpenVINO IR&#xff08;中间表示&#xff09; - OpenVINO™的专有格式&#xff0c;可以完全利用其全部功能。 ONNX和PaddlePaddle - 直接支持的格式&#xff0c;这意味着它们可以在OpenVI…

DT7遥控DBUS协议解析

文章目录 运行环境&#xff1a;1.1 DBUS协议解析1)DT7遥控2)配置串口引脚3)配置串口接收DMA 2.1例程代码移植1)例程移动到 Inc 和 Src2)makefile添加.c文件 3.1核心代码解释4.1代码修改1)bsp_rc.c 和 remote_control.c2)调用代码 5.1调试1)硬件接线2)串口工具监视拨杆数据 运行…

【C进阶】-- 字符串函数(1)

目录 0. 前言 1. 函数介绍 1.1 strlen 1.1.1主动改变\0的位置 ✅"strlen函数的返回类型是size_t - 无符号整型"✅ 当使用strlen函数但不引用头文件时&#xff0c;执行结果超出预料: 求字符串长度的方法&#x1f4a5; 1.计数器 2.递归 3.指针 - 指针 1.2 st…

HBase安装下载与集群(高可用)

一、准备 1.1 安装zookeeper zookeeper 安装下载与集群 1.2 安装HADOOP hadoop搭建集群搭建 1.3下载HBase https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/ 二、正常部署 2.1 检查是否正常启动 2.2解压 tar -zvxf hbase-2.4.11-bin.tar.gz2.3配置环境变量 vim /…

高效的工作团队都在使用什么工具?

、 移动互联网时代&#xff0c;企业需要开源节流&#xff0c;需要提高员工整体工作效率。尤其对于互联网公司来说&#xff0c;要快速发展业务&#xff0c;更需要让团队工作简单、方便、高效。然而大多公司都面临以下低效阻碍&#xff1a;跨公司、跨部门沟通合作困难。不同部门和…

2、Flutter布局和状态管理

一、Flutter布局之Row&Column 1.1 Container的center属性: 让子控件在父控件的中间显示 Container(color: Colors.yellow,//1.Center让子部件在父控件中间child: Center(child: Text(Layout Center)),); 1.2 alignment让子控件相对父控件位置,取值范围在-1&#xff5e;1…

Mysql索引(1):索引概述

1 介绍 索引&#xff08;index&#xff09;是帮助MySQL高效获取数据的数据结构(有序)。在数据之外&#xff0c;数据库系统还维护着满足特定查找算法的数据结构&#xff0c;这些数据结构以某种方式引用&#xff08;指向&#xff09;数据&#xff0c; 这样就可以在这些数据结构上…

【半监督学习】Match系列.1

半监督学习(SSL) 半监督学习(SSL). 让学习器不依赖外界交互、自动地利用未标记样本来提升学习性能. 即在少量样本标签的引导下, 能够充分利用大量无标签样本提高学习性能, 避免了数据资源的浪费, 同时解决了有标签样本较少时监督学习方法泛化能力不强和缺少样本标签引导时无监…

YoloV8涨点神器:CFPNet-ECVBlock的小目标检测,即插即用,助力检测涨点

1.Centralized Feature Pyramid for Object Detection 论文地址: https://arxiv.org/abs/2210.02093 1.摘要: CFPNet简介 CFPNet即插即用,助力检测涨点,YOLOX/YOLOv5/YOLOV7均有效 1.3 Centralized Feature Pyramid (CFP) 如图2所示,CFP主要由以下部分组成:输入图像、…

<IBM AIX><ERRPT><No.001>《出现E86653C3、49183216、8003764C告警的处理 20230506》

《出现E86653C3、49183216、8003764C告警的处理 20230506》 1 现象2 分析3 结论4 引申 1 现象 服务器出现errpt告警&#xff0c;告警为E86653C3、49183216、8003764C。 2 分析 1、hdisk1对应的VG&#xff0c;为rootvg。 lspv |grep hdisk12、查看VG状态 lsvg rootvg说明…

聊聊压电材料高温介电温谱仪所知道的那些事(GWJDN-600A)

GWJDN-600A型压电材料高温介电温谱仪 关键词&#xff1a;单通道&#xff0c;双通道&#xff0c;四通道&#xff0c;高低温 GWJDN-600A压电材料高温介电温谱仪本高频介电温谱系统主要用于绝缘材料在不同温度不同频率下的电学性能测试&#xff0c;系统包含高温炉膛&#xff0c;阻…

【云原生】k8s集群部署Rook+Ceph云原生存储

文章目录 一、Rook介绍二、Ceph介绍三、部署Rook和Ceph3.1 前置准备3.2 部署Rook3.3 部署Ceph集群3.4 部署ceph dashboard 四、部署Rook工具箱五、部署RBD StorageClass 一、Rook介绍 Rook 官网地址&#xff1a;https://rook.io 是一个自管理的分布式存储编排系统&#xff0c;…

c++基础学习Num04

目录 基于for循环 一维数组 二维数组理解 c语言的null和c的null 基于for循环 for(ELEMTYPE val:array){}ELEMTYPE:是范围变量的类型。通常使用auto自动转换范围变量类型 val:范围变量的名称。通过迭代依次接收数组中的元素值 array:容器&#xff0c;注意这里的array必须是…

ctfshow 每周大挑战 RCE极限挑战 2

目录 题目解题步骤1.跑一下正则2.变量自增3.最终解题payload 一点多余的思考 题目 解题步骤 1.跑一下正则 本着能懒就懒的原则&#xff0c;就不写Python了&#xff08;提一下这个主要是我一开始想的是写Python呜呜呜&#xff09;&#xff0c;直接写php&#xff0c;还能复制粘…

C生万物 | 指针入门到进阶就看这篇了【十万字吐血整理,收藏学习】

文章篇幅较长&#xff0c;可前往电脑端进行学习&#x1f4bb; 之前很多粉丝私信我说C语言指针怎么这么难&#xff0c;看了很多视频都学不懂&#xff0c;于是我写了一篇有关指针从入门到进阶的教学&#xff0c;帮助那些对指针很困扰的同学有一个好的学习途径&#xff0c;下面是本…

基于JavaWeb实现的学生宿舍管理系统

【简介】 本系统是基于Java实现的学生宿舍管理系统&#xff0c;前端&#xff1a;Vue&#xff1b;后端&#xff1a;SpringBoot Mybatis Redis Mysql&#xff1b;系统环境&#xff1a;jdk1.8 | mysql | redis | nodejs14。有包含登录在内的十大功能模块&#xff0c;三个访问角…

详解事务模式和 Lua 脚本,带你吃透 Redis 事务

先说结论&#xff1a; Redis 的事务模式具备如下特点&#xff1a; 保证隔离性&#xff1b;无法保证持久性&#xff1b;具备了一定的原子性&#xff0c;但不支持回滚&#xff1b;一致性的概念有分歧&#xff0c;假设在一致性的核心是约束的语意下&#xff0c;Redis 的事务可以…

Vuex从了解到实际运用(一)彻底搞懂什么是Vuex

vuex从了解到实际运用——彻底搞懂什么是vuex 知识回调&#xff08;不懂就看这儿&#xff01;&#xff09;场景复现核心干货什么是vuex全局状态管理使用状态管理工具后的好处vuex的实现原理vuex的组件通信1.多级组件通信2.同级组件通信使用vuex进行组件通信 关于vuex的小结 知识…