当前位置: 首页 > news >正文

Spring-事务2

文章目录

  • 前言
  • 一、事务的特性(ACID)
  • 二、事务的隔离级别
  • 三、spring中的事务
      • 平台事务管理器.
      • 事务定义
        • ISOLation_XXX:**事务隔离级别.**
        • PROPAGATION_XXX:**事务的传播行为**.
      • 事务状态
    • 关系:
  • 四、使用XML文件配置事务
    • 1、 搭建环境
    • 2、 配置及业务编写
    • 3、 测试
  • 五、使用注解形式进行事务开发
  • 总结


前言

事务是逻辑上的一组操作的集合,要么全部成功,要么全部失败。在实际的业务场景中,事务的应用场景范围很广泛,例如转账,订单,支付等


一、事务的特性(ACID)

事务有四大特性:

  • 原子性:事务不可分割
  • 一致性:事务执行的前后,数据完整性保持一致.
  • 隔离性:一个事务执行的时候,不应该受到其他事务的打扰
  • 持久性:一旦结束,数据就永久的保存到数据库.

二、事务的隔离级别

在实际的开发中,可能会出现以下几种由数据操作引起的异常情况:
如果不考虑隔离性:

  • 脏读:一个事务读到另一个事务未提交数据
  • 不可重复读:一个事务读到另一个事务已经提交数据(update)导致一个事务多次查询结果不一致
  • 虚读:一个事务读到另一个事务已经提交数据(insert)导致一个事务多次查询结果不一致

事务存在几种隔离级别:

  • 未提交读:以上情况都有可能发生。
  • 已提交读:避免脏读,但不可重复读,虚读是有可能发生。
  • 可重复读:避免脏读,不可重复读,但是虚读有可能发生。
  • 串行化:避免以上所有情况.

三、spring中的事务

后端分层开发中,事务应用于Service层中。spring提供了事务管理API

平台事务管理器.

PlatformTransactionManager

  • getTransaction(TransactionDefinition definition) :开启事务
  • rollback(TransactionStatus status) :回滚事务
  • commit(TransactionStatus status) :提交事务

Spring为不同的持久化框架提供了不同PlatformTransactionManager接口实现

使用Spring JDBC或iBatis 进行持久化数据时使用(重点)

  • org.springframework.jdbc.datasource.DataSourceTransactionManager

使用Hibernate进行持久化数据时使用

  • org.springframework.orm.hibernate.HibernateTransactionManager

使用JPA进行持久化时使用

  • org.springframework.orm.jpa.JpaTransactionManager

当持久化机制是Jdo时使用

  • org.springframework.jdo.JdoTransactionManager

使用一个JTA实现来管理事务,在一个事务跨越多个资源时必须使用

  • org.springframework.transaction.jta.JtaTransactionManager

事务定义

TransactionDefinition

ISOLation_XXX:事务隔离级别.

ISOLATION_DEFAULT:默认级别. Mysql --> repeatable_read | Oracle -->> read_commited
级别如下:

  • ISOLATION_READ_UNCOMMITTED : 读未提交
  • ISOLATION_READ_COMMITTED : 读已提交
  • ISOLATION_REPEATABLE_READ :可重复读
  • ISOLATION_SERIALIZABLE :串行化

PROPAGATION_XXX:事务的传播行为.

事务的传播行为是用来解决实际开发中的问题
传播行为是指:解决业务层调用事务的关系。

  • PROPAGATION_REQUIRED: 支持当前事务,如果不存在 就新建一个

A,B 如果A有事务,B使用A的事务,如果A没有事务,B就开启一个新的事务.(A,B是在一个事务中。)

  • PROPAGATION_SUPPORTS: 支持当前事务,如果不存在,就不使用事务

A,B 如果A有事务,B使用A的事务,如果A没有事务,B就不使用事务.

  • PROPAGATION_MANDATORY: 支持当前事务,如果不存在,抛出异常

A,B 如果A有事务,B使用A的事务,如果A没有事务,抛出异常.

  • PROPAGATION_REQUIRES_NEW: 如果有事务存在,挂起当前事务,创建一个新的事务

A,B 如果A有事务,B将A的事务挂起,重新创建一个新的事务.(A,B不在一个事务中.事务互不影响.)

  • PROPAGATION_NOT_SUPPORTED: 以非事务方式运行,如果有事务存在,挂起当前事务

A,B 非事务的方式运行,A有事务,就会挂起当前的事务.

  • PROPAGATION_NEVER: 以非事务方式运行,如果有事务存在,抛出异常

  • PROPAGATION_NESTED: 如果当前事务存在,则嵌套事务执行

基于SavePoint技术.
A,B A有事务,A执行之后,将A事务执行之后的内容保存到SavePoint.B事务有异常的话,用户需要自己设置事务提交还是回滚.

  • 常用:(重点)
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRES_NEW
    PROPAGATION_NESTED

事务状态

TransactionStatus

  • 是否有保存点

  • 是否是一个新的事务

  • 事务是否已经提交

关系:

关系:PlatformTransactionManager通过TransactionDefinition设置事务相关信息管理事务,管理事务过程中,产生一些事务状态,状态由TransactionStatus记录。

四、使用XML文件配置事务

spring支持声明式事务管理,只需要配置文件,不需要额外的编写代码
演示如下:

1、 搭建环境

创建account表并插入两条数据

CREATE TABLE `account` (`id` int(11) NOT NULL AUTO_INCREMENT,`money` double DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;INSERT INTO `account` VALUES ('1',  '1000');
INSERT INTO `account` VALUES ('2',  '1000');

新建项目略
导入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>com.wmj</groupId><artifactId>SpringTX</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><!-- spring相关依赖,版本必须保持一致 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.24</version></dependency><!--spring数据连接支持 --><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.24</version></dependency><!--aop支持 --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.9.1</version></dependency><!-- 事务 --><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.3.24</version></dependency><!-- mybatis相关依赖 --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.11</version></dependency><!-- myabtis整合spring依赖,必须导入 --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.7</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.31</version></dependency><!--德鲁伊数据连接池支持 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.9</version></dependency><!--lombok注解支持 --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.24</version></dependency><!--log4j日志 --><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><!--单元测试 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency></dependencies>
</project>

2、 配置及业务编写

配置mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><!-- 配置日志 --><settings><setting name="logImpl" value="LOG4J"/></settings></configuration>

配置日志

log4j.rootLogger=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

配置数据源

db.username = 帐号
db.password = 密码
db.url = jdbc:mysql:///库名?serverTimezone=Asia/Shanghai&characterEncoding=UTF8
db.driverClassName = com.mysql.cj.jdbc.Driver

搭建后端业务代码

控制层

package com.wmj.controller;import com.wmj.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;/*** --效率,是成功的核心关键--** @Author lzl* @Date 2023/2/13 16:04*/
@Controller
public class TestController {@Autowiredprivate TestService service;public void testTx(Integer id1,Integer id2,Double money){service.transferMoney(id1,id2,money);}
}

业务层接口及其实现类

package com.wmj.service;/*** --效率,是成功的核心关键--** @Author lzl* @Date 2023/2/13 16:10*/public interface TestService {void transferMoney(Integer id1, Integer id2, Double money);
}
package com.wmj.service.impl;import com.wmj.mapper.TestMapper;
import com.wmj.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** --效率,是成功的核心关键--** @Author lzl* @Date 2023/2/13 16:11*/
@Service
public class TestServiceImpl implements TestService {@Autowiredprivate TestMapper mapper;@Overridepublic void transferMoney(Integer id1, Integer id2, Double money) {mapper.dmoney(id1,money);int a =  1/0;mapper.amoney(id2,money);}
}

持久层接口及其xml数据访问

package com.wmj.mapper;import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;/*** --效率,是成功的核心关键--** @Author lzl* @Date 2023/2/13 16:12*/
@Repository
public interface TestMapper {Integer dmoney(@Param("id1") Integer id1, @Param("money") Double money);Integer amoney(@Param("id2") Integer id2, @Param("money") Double money);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.wmj.mapper.TestMapper"><update id="dmoney">update account set money = money - #{money} where id = #{id1}</update><update id="amoney">update account set money = money + #{money} where id = #{id2}</update>
</mapper>

配置spring核心配置文件application.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!-- bean definitions here --><!-- 扫描包下的注解 --><context:component-scan base-package="com.wmj"></context:component-scan><!-- 引入db.properties配置文件 --><context:property-placeholder location="classpath:db.properties"></context:property-placeholder><!-- 配置数据库链接 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="username" value="${db.username}"></property><property name="password" value="${db.password}"></property><property name="url" value="${db.url}"></property><property name="driverClassName" value="${db.driverClassName}"></property></bean><!-- 配置SqlSession --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- dataSource属性(必选属性) --><property name="dataSource" ref="dataSource"></property><!-- configLocation属性配置mybatis-config.xml(非必选属性)--><property name="configLocation" value="classpath:mybatis-config.xml"></property><!-- mapperLocations属性用于配置Mapper.xml文件所在位置 (非必选属性)--><property name="mapperLocations" value="classpath:mapper/*.xml"></property></bean><!-- 扫描Mapper --><bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.wmj.mapper"></property></bean><!-- 事务核心管理器,封装了所有事务操作. 依赖于连接池 --><bean name="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!-- 配置事务通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!-- 企业中配置CRUD方法一般使用方法名+通配符*的形式配置通知,此时类中的方法名要和配置的方法名一致 --><!-- 以方法为单位,指定方法应用什么事务属性isolation:用于指定事务的隔离级别。默认值是DEFAULT,表示使用数据库的默认隔离级别。propagation:用于指定事务的传播行为。默认值是REQUIRED,表示一定会有事务,增删改的选择。查询方法可以选择SUPPORTS。read-only:用于指定事务是否只读。只有查询方法才能设置为true。默认值是false,表示读写。timeout:用于指定事务的超时时间,默认值是-1,表示永不超时。如果指定了数值,以秒为单位。rollback-for:用于指定一个异常,当产生该异常时,事务回滚,产生其他异常时,事务不回滚。没有默认值。表示任何异常都回滚。no-rollback-for:用于指定一个异常,当产生该异常时,事务不回滚,产生其他异常时事务回滚。没有默认值。表示任何异常都回滚。--><tx:method name="transferMoney" isolation="REPEATABLE_READ"propagation="REQUIRED" read-only="false" /></tx:attributes></tx:advice><!-- 配置织入 --><aop:config><!-- 配置切点表达式 --><aop:pointcut expression="execution(* com.wmj.service.impl.*ServiceImpl.*(..))"id="txPc" /><!-- 配置切面 : 通知+切点 advice-ref:通知的名称 pointcut-ref:切点的名称 --><aop:advisor advice-ref="txAdvice" pointcut-ref="txPc" /></aop:config></beans>

3、 测试

package com.test;import com.wmj.controller.TestController;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** --效率,是成功的核心关键--** @Author lzl* @Date 2023/2/13 16:02*/public class Demo1 {@Testpublic void testTX(){ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("application.xml");TestController controller = (TestController)applicationContext.getBean("testController");controller.testTx(1,2,200.00);}
}

执行结果:
当没有遇到异常时,转账能正常执行,不在演示,此处演示当遇到异常时的事务效果
代码执行前数据库:
在这里插入图片描述

在这里插入图片描述
当遇到异常,代码终止执行,此时数据库

在这里插入图片描述
转账并没有进行提交,此时说明我们的事务配置成功!

五、使用注解形式进行事务开发

spring给我们提供了事务注解开发的方式,大大减少了代码编写,十分方便

创建项目配置基本与上方相同,我们将application.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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- bean definitions here --><!-- 导入外部配置文件 db.properties --><context:property-placeholder location="classpath:db.properties"></context:property-placeholder><!-- 配置数据源对象 --><bean id="datasource" class="com.alibaba.druid.pool.DruidDataSource"><!-- 导入 db.properties 中的值--><property name="username" value="${db.username}"></property><property name="password" value="${db.password}"></property><property name="url" value="${db.url}"></property><property name="driverClassName" value="${db.driver}"></property></bean><!-- 扫描对应包下的注解 --><context:component-scan base-package="com.wmj"></context:component-scan><!-- 配置sqlSessionFactory --><bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 必选配置 --><property name="dataSource" ref="datasource"></property><!-- 非必选属性,根据自己需求去配置 --><!-- 导入 mybatis-config.xml --><property name="configLocation" value="classpath:mybatis-config.xml"></property><!-- 导入 Mapper.xml 文件,classpath后面不能有空格 --><property name="mapperLocations" value="classpath:mapper/*.xml"></property></bean><!-- 扫描 Mapper 接口,生成代理对象 --><bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 指定扫描的具体位置 --><property name="basePackage" value="com.wmj.mapper"></property></bean><!-- 配置事务 --><!-- 事务平台管理器,封装了所有的事务操作,依赖数据源 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="datasource"></property></bean><!-- 开启注解驱动事务支持 --><tx:annotation-driven></tx:annotation-driven></beans>

将业务实现类改造如下:

package com.wmj.service.impl;import com.wmj.mapper.AccountMapper;
import com.wmj.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;/*** @Transactional 配置事务* 可以写在类上,也可以写在方法上*/
//@Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,readOnly = false)
@Service
package com.wmj.service.impl;import com.wmj.mapper.TestMapper;
import com.wmj.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** --效率,是成功的核心关键--** @Author lzl* @Date 2023/2/13 16:11*/
/*** @Transactional 配置事务* 可以写在类上,也可以写在方法上*/
//@Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,readOnly = false)
@Service
public class TestServiceImpl implements TestService {@Autowiredprivate TestMapper mapper;@Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,readOnly = false)@Overridepublic void transferMoney(Integer id1, Integer id2, Double money) {mapper.dmoney(id1,money);int a =  1/0;mapper.amoney(id2,money);}
}

测试略


总结

本次主要记录了spring的事务支持,及其两种开发方式。再会!!!

相关文章:

Spring-事务2

文章目录前言一、事务的特性&#xff08;ACID&#xff09;二、事务的隔离级别三、spring中的事务平台事务管理器.事务定义ISOLation_XXX&#xff1a;**事务隔离级别.**PROPAGATION_XXX&#xff1a;**事务的传播行为**.事务状态关系&#xff1a;四、使用XML文件配置事务1、 搭建…...

Windows Git Bash 配置

Windows Git Bash 配置 本文参考的文章&#xff1a; 在 Windows 的 Git Bash 中使用包管理器 - iris (ginshio.org)Git bash 安装 pacman & Windows 解压 zst 文件 | 伪斜杠青年 (lckiss.com) 一、Git的安装 Git 的安装应该是都会的&#xff0c;但还是应该说以下&#…...

java代码整合kettle9.3实现读取表中的数据,生成excel文件

java代码整合kettle9.3实现读取表中的数据&#xff0c;生成excel文件 1.简介 本次使用java代码整合kettle9.3版本&#xff0c;数据库使用mysql。 2.jar包导入 项目需要依赖部分kettle中的jar包&#xff0c;请将这部分jar包自行导入maven仓库。 <dependency><groupId…...

分享微信点餐小程序搭建步骤_微信点餐功能怎么做

线下餐饮实体店都开始摸索发展网上订餐服务。最多人选择的是入驻外卖平台&#xff0c;但抽成高&#xff0c;推广还要另买流量等问题&#xff0c;也让不少商家入不敷出。在这种情况下&#xff0c;建立自己的微信订餐小程序&#xff0c;做自己的私域流量是另一种捷径。那么&#…...

4、数组、切片、map、channel

目录一、数组二、切片三、map四、channel五、引用类型一、数组 数组&#xff1a; 数组是块连续的内存空间&#xff0c;在声明的时候必须指定长度&#xff0c;且长度不能改变所以数组在声明的时候就可以把内存空间分配好&#xff0c;并赋上默认值&#xff0c;即完成了初始化数组…...

270 uuid

270 uuid 用途 For the creation of RFC4122 UUIDs 可靠性 10000 星星 适应于浏览器或者服务器 官网链接 https://www.npmjs.com/package/uuid https://github.com/uuidjs/uuid 基本使用 import { v4 as uuidv4 } from uuid; uuidv4(); // ⇨ 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3d…...

2023最新简历模板免费下载

下面分享5个简历模板网站&#xff0c;免费下载&#xff0c;建议收藏&#xff01; 2023用最漂亮的简历模板&#xff0c;让面试官眼前一亮。 1、菜鸟图库 个人简历模板|WORD文档模板免费下载 - 菜鸟图库 菜鸟图库除了有超多设计类素材之外&#xff0c;还有很多办公类素材&#…...

【CSS】元素居中总结-水平居中、垂直居中、水平垂直居中

【CSS】元素居中一、 水平居中1.行内元素水平居中&#xff08;1&#xff09;text-align2.块级元素水平居中2.1 margin&#xff08;1&#xff09;margin2.2布局&#xff08;1&#xff09;flex justify-content&#xff08;推荐&#xff09;&#xff08;2&#xff09; flexmargin…...

spring实现AOP

文章目录前言一、AOP的底层实现原理二、AOP的两种开发模式1.使用xml配置文件1.1 添加AOP依赖1.2 创建UserService1.3创建UserServiceImpl1.4创建通知类1.5 创建applicationContext.xml&#xff08;添加aop约束&#xff09;1.6 测试2.使用注解开发2.1 创建bean.xml文件配置注解方…...

neovim搭建cpp环境

文章目录Windowns下NeoVim搭建cpp环境NeoVim安装插件vim-plugindentLinevim-airlinectagstagbarcoc.vimWindowns下NeoVim搭建cpp环境 在开发过程中习惯在DIE环境中使用vim作为编辑器&#xff0c;在单独的编辑器也常使用gvim图形化编辑器。最近看到NeoVim的特性及兼容性方面不输…...

SpringBoot AES加密 PKCS7Padding 模式

AES 简介&#xff1a;DES 全称为Data Encryption Standard&#xff0c;即数据加密标准&#xff0c;是一种使用密钥加密的块算法&#xff0c;1977年被美国联邦政府的国家标准局确定为联邦资料处理标准&#xff08;FIPS&#xff09; AES 密码学中的高级加密标准&#xff08;Advan…...

按键输入驱动

目录 一、硬件原理 二、添加设备树 1、创建pinctrl 2、创建节点 3、检查 编译复制 三、修改工程模板​编辑 四、驱动编写 1、添加keyio函数 2、添加调用 3、驱动出口函数添加释放 4、添加原子操作 5、添加两个宏定义 6、初始化原始变量 7、打开操作 8、读操作 总体代…...

2023年第七周总周结 | 开学倒数第三周

为什么要做周总结&#xff1f; 1.避免跳相似的坑 2.客观了解上周学习进度并反思&#xff0c;制定可完成的下周规划 一、上周问题解决情况 晚上熬夜导致第二天学习状态不好 这周熬夜一天&#xff0c;晚上帮亲戚修手机到22:30&#xff0c;可能是晚上自己的事什么都没做&#xff…...

Springboot扫描注解类

Springboot扫描注解类的入口在AbstractApplicationContext的refresh中&#xff0c;对启动步骤不太了解的&#xff0c;可参考https://blog.csdn.net/leadseczgw01/article/details/128930925BeanDefinitionRegistryPostProcessor接口有多个实现类&#xff0c;扫描Controller、Se…...

Apache日志分析器

您的Apache HTTP服务器生成的日志数据是信息的宝库。使用这些信息&#xff0c;您可以判断您服务器的使用情况、找出漏洞所在&#xff0c;并设法改进服务器结构和整体性能。审核您的Apache日志可在以下情况派上用场&#xff0c;其中包括&#xff1a;识别和纠正频繁出现的错误以增…...

啪,还敢抛出异常

&#x1f649; 作者简介&#xff1a; 全栈领域新星创作者 &#xff1b;天天被业务折腾得死去活来的同时依然保有对各项技术热忱的追求&#xff0c;把分享变成一种习惯&#xff0c;再小的帆也能远航。 &#x1f3e1; 个人主页&#xff1a;xiezhr的个人主页 前言 去年又重新刷了…...

Apache JMeter 5.5 下载安装以及设置中文教程

Apache JMeter 5.5 下载安装以及设置中文教程JMeter下载Apache JMeter 5.5配置环境变量查看配置JDK配置JMeter环境变量运行JMeter配置中文版一次性永久设置正文JMeter 下载Apache JMeter 5.5 官方网站&#xff1a;Apache JMeter 官网 版本介绍&#xff1a; 版本中一个是Bina…...

string类模拟实现

了解过string常用接口后&#xff0c;接下来的任务就是模拟实现string类。 目录 VS下的string结构 默认成员函数和简单接口 string结构 c_str()、size()、capacity()、clear()、swap() 构造函数 拷贝构造函数 赋值重载 析构函数 访问及遍历 容量操作 reserve resize …...

cadence SPB17.4 S032 - allegro - 保存/载入光绘层定义

文章目录cadence SPB17.4 S032 - allegro - 保存/载入光绘层定义概述保存光绘层在新板子中载入已经保存的相同类型老板子定义好的光绘层定义文件碎碎念ENDcadence SPB17.4 S032 - allegro - 保存/载入光绘层定义 概述 以前布线完成, 准备出板厂文件时, 总是要手工重新建立光绘…...

微服务实战--高级篇:分布式缓存 Redis

分布式缓存 – 基于Redis集群解决单机Redis存在的问题 单机的Redis存在四大问题&#xff1a; 1.Redis持久化 Redis有两种持久化方案&#xff1a; RDB持久化AOF持久化 1.1.RDB持久化 RDB全称Redis Database Backup file&#xff08;Redis数据备份文件&#xff09;&#xf…...

Redis相关知识总结(缓存雪崩,缓存穿透,缓存击穿,Redis实现分布式锁,如何保持数据库和缓存一致)

文章目录 1.什么是Redis&#xff1f;2.为什么要使用redis作为mysql的缓存&#xff1f;3.什么是缓存雪崩、缓存穿透、缓存击穿&#xff1f;3.1缓存雪崩3.1.1 大量缓存同时过期3.1.2 Redis宕机 3.2 缓存击穿3.3 缓存穿透3.4 总结 4. 数据库和缓存如何保持一致性5. Redis实现分布式…...

循环冗余码校验CRC码 算法步骤+详细实例计算

通信过程&#xff1a;&#xff08;白话解释&#xff09; 我们将原始待发送的消息称为 M M M&#xff0c;依据发送接收消息双方约定的生成多项式 G ( x ) G(x) G(x)&#xff08;意思就是 G &#xff08; x ) G&#xff08;x) G&#xff08;x) 是已知的&#xff09;&#xff0…...

从深圳崛起的“机器之眼”:赴港乐动机器人的万亿赛道赶考路

进入2025年以来&#xff0c;尽管围绕人形机器人、具身智能等机器人赛道的质疑声不断&#xff0c;但全球市场热度依然高涨&#xff0c;入局者持续增加。 以国内市场为例&#xff0c;天眼查专业版数据显示&#xff0c;截至5月底&#xff0c;我国现存在业、存续状态的机器人相关企…...

macOS多出来了:Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用

文章目录 问题现象问题原因解决办法 问题现象 macOS启动台&#xff08;Launchpad&#xff09;多出来了&#xff1a;Google云端硬盘、YouTube、表格、幻灯片、Gmail、Google文档等应用。 问题原因 很明显&#xff0c;都是Google家的办公全家桶。这些应用并不是通过独立安装的…...

页面渲染流程与性能优化

页面渲染流程与性能优化详解&#xff08;完整版&#xff09; 一、现代浏览器渲染流程&#xff08;详细说明&#xff09; 1. 构建DOM树 浏览器接收到HTML文档后&#xff0c;会逐步解析并构建DOM&#xff08;Document Object Model&#xff09;树。具体过程如下&#xff1a; (…...

Keil 中设置 STM32 Flash 和 RAM 地址详解

文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

【HTML-16】深入理解HTML中的块元素与行内元素

HTML元素根据其显示特性可以分为两大类&#xff1a;块元素(Block-level Elements)和行内元素(Inline Elements)。理解这两者的区别对于构建良好的网页布局至关重要。本文将全面解析这两种元素的特性、区别以及实际应用场景。 1. 块元素(Block-level Elements) 1.1 基本特性 …...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)

考察一般的三次多项式&#xff0c;以r为参数&#xff1a; p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]&#xff1b; 此多项式的根为&#xff1a; 尽管看起来这个多项式是特殊的&#xff0c;其实一般的三次多项式都是可以通过线性变换化为这个形式…...

认识CMake并使用CMake构建自己的第一个项目

1.CMake的作用和优势 跨平台支持&#xff1a;CMake支持多种操作系统和编译器&#xff0c;使用同一份构建配置可以在不同的环境中使用 简化配置&#xff1a;通过CMakeLists.txt文件&#xff0c;用户可以定义项目结构、依赖项、编译选项等&#xff0c;无需手动编写复杂的构建脚本…...