Spring事务管理与模板对象

1.事务管理

1.事务回顾

事务指数据库中多个操作合并在一起形成的操作序列

事务的作用

当数据库操作序列中个别操作失败时,提供一种方式使数据库状态恢复到正常状态(A),保障数据库即使在异常状态下仍能保持数据一致性(C)(要么操作前状态,要么操作后状态)。

当出现并发访问数据库时,在多个访问间进行相互隔离,防止并发访问操作结果互相干扰(I

事务的特征(ACID)

原子性(Atomicity)指事务是一个不可分割的整体,其中的操作要么全执行或全不执行

一致性(Consistency)事务前后数据的完整性必须保持一致

隔离性(Isolation)事务的隔离性是多个用户并发访问数据库时,数据库为每一个用户开启的事务,不能被其他事务的操作数据所干扰,多个并发事务之间要相互隔离

持久性(Durability)持久性是指一个事务一旦被提交,它对数据库中数据的改变就是永久性的,接下来即使数据库发生故障也不应该对其有任何影响

事务的隔离级

脏读:允许读取未提交的信息

原因:Read uncommitted

解决方案: (表级读锁)

不可重复读:读取过程中单个数据发生了变化

解决方案: Repeatable read (行级写锁)

幻读:读取过程中数据条目发生了变化

解决方案: Serializable(表级写锁)

2.Spring事务核心对象

J2EE开发使用分层设计的思想进行,对于简单的业务层转调数据层的单一操作,事务开启在业务层或者数据层并无太大差别,当业务中包含多个数据层的调用时,需要在业务层开启事务,对数据层中多个操作进行组合并归属于同一个事务进行处理

Spring为业务层提供了整套的事务解决方案

        PlatformTransactionManager

        TransactionDefinition

        TransactionStatus

PlatformTransactionManager(平台事务管理器)

这是一个接口

平台事务管理器实现类:

DataSourceTransactionManager   适用于Spring JDBC或MyBatis

HibernateTransactionManager   适用于Hibernate3.0及以上版本

JpaTransactionManager   适用于JPA

JdoTransactionManager   适用于JDO

JtaTransactionManager   适用于JTA

JPA(Java Persistence API)Java EE 标准之一,为POJO提供持久化标准规范,并规范了持久化开发的统一API,符合JPA规范的开发可以在不同的JPA框架下运行

JDO(Java Data Object )是Java对象持久化规范,用于存取某种数据库中的对象,并提供标准化API。与JDBC相比,JDBC仅针对关系数据库进行操作,JDO可以扩展到关系数据库、文件、XML、对象数据库(ODBMS)等,可移植性更强

JTA(Java Transaction API)Java EE 标准之一,允许应用程序执行分布式事务处理。与JDBC相比,JDBC事务则被限定在一个单一的数据库连接,而一个JTA事务可以有多个参与者,比如JDBC连接、JDO 都可以参与到一个JTA事务中

此接口定义了事务的基本操作

获取事务

TransactionStatus getTransaction(TransactionDefinition definition)

提交事务 

void commit(TransactionStatus status) 

回滚事务 

void rollback(TransactionStatus status)

TransactionDefinition(事务定义的接口)

此接口定义了事务的基本信息

获取事务定义名称

String getName()

获取事务的读写属性

boolean isReadOnly()

获取事务隔离级别

int getIsolationLevel()

获事务超时时间

int getTimeout()

获取事务传播行为特征

int getPropagationBehavior()

TransactionStatus(事务状态的接口)

此接口定义了事务在执行过程中某个时间点上的状态信息及对应的状态操作

获取事务是否处于新开启事务状态

boolean isNewTransaction()

获取事务是否处于已完成状态

boolean isCompleted()

获取事务是否处于回滚状态

boolean isRolbackOnly()

刷新事务状态

void flush()

获取事务是否具有回滚存储点

boolean hasSavepoint()

设置事务处于回滚状态

void setRollbackOnly()

3.事务控制方式

编程式

声明式(XML)

声明式(注解)

4.案例环境

银行转账业务说明

银行转账操作中,涉及从A账户到B账户的资金转移操作。数据层仅提供单条数据的基础操作,未设计多账户间的业务操作

package com.dao;import org.apache.ibatis.annotations.Param;public interface AccountDao {/** 入账操作* name  入账用户名* money  入账金额*/void inMoney(@Param("name") String name, @Param("money") Double money);/** 入账操作* name  出账用户名* money  出账金额*/void outMoney(@Param("name") String name, @Param("money") Double money);}
package com.domain;public class Account {private Integer id;private String name;private Double money;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Double getMoney() {return money;}public void setMoney(Double money) {this.money = money;}@Overridepublic String toString() {return "Account{" +"id=" + id +", name='" + name + '\'' +", money=" + money +'}';}
}
package com.service;public interface AccountService {/** 转账操作* outName  出账用户名* inName  入账用户名* money   转账金额*/public void transfer(String outName, String inName, Double money);
}
package com.service.impl;import com.dao.AccountDao;
import com.service.AccountService;public class AccountServiceImpl implements AccountService {private AccountDao accountDao;public void setAccountDao(AccountDao accountDao) {this.accountDao = accountDao;}@Overridepublic void transfer(String outName, String inName, Double money) {accountDao.inMoney(outName,money);accountDao.outMoney(inName,money);}
}

<?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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><context:property-placeholder location="classpath:*.properties"/><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driver}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><bean id="accountService" class="com.service.impl.AccountServiceImpl"><property name="accountDao" ref="accountDao"/></bean><bean class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="typeAliasesPackage" value="com.domain"/></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.dao"/></bean>
</beans>
<?xml version="1.0" encoding="UTF-8" ?>
<!--MyBatis的DTD约束-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dao.AccountDao"><update id="inMoney">update account set money = money + #{money} where name = #{name}</update><update id="outMoney">update account set money = money - #{money} where name = #{name}</update>
</mapper>
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring_db?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false
jdbc.username=root
jdbc.password=123456

5.使用AOP控制事务 (XML)

将业务层的事务处理功能抽取出来制作成AOP通知,利用环绕通知运行期动态织入

范例

public Object tx(ProceedingJoinPoint pjp) throws Throwable {DataSourceTransactionManager dstm = new DataSourceTransactionManager();dstm.setDataSource(dataSource);TransactionDefinition td = new DefaultTransactionDefinition();TransactionStatus ts = dstm.getTransaction(td);Object ret = pjp.proceed(pjp.getArgs());dstm.commit(ts);return ret;
}
<bean id="txAdvice" class="com.aop.TxAdvice"><property name="dataSource" ref="dataSource"/>
</bean>

使用aop:advisor在AOP配置中引用事务专属通知类

<aop:config><aop:pointcut id="pt" expression="execution(* *..transfer(..))"/><aop:aspect ref="txAdvice"><aop:around method="tx" pointcut-ref="pt"/></aop:aspect>
</aop:config>

样例

package com.service.impl;import com.dao.AccountDao;
import com.service.AccountService;
import javafx.application.Platform;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;import javax.sql.DataSource;public class AccountServiceImpl implements AccountService {private AccountDao accountDao;public void setAccountDao(AccountDao accountDao) {this.accountDao = accountDao;}/*private DataSource dataSource;public void setDataSource(DataSource dataSource) {this.dataSource = dataSource;}*/@Overridepublic void transfer(String outName, String inName, Double money) {/* //开启事务PlatformTransactionManager ptm = new DataSourceTransactionManager(dataSource);//事务定义TransactionDefinition td = new DefaultTransactionDefinition();//事务状态TransactionStatus ts = ptm.getTransaction(td);*/accountDao.inMoney(outName,money);//int i = 1/0;accountDao.outMoney(inName,money);/*ptm.commit(ts);*/}
}

package com.aop;import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;import javax.sql.DataSource;public class TxAdvice {private DataSource dataSource;public void setDataSource(DataSource dataSource) {this.dataSource = dataSource;}public Object transactionManager(ProceedingJoinPoint pjp) throws  Throwable{//开启事务PlatformTransactionManager ptm = new DataSourceTransactionManager(dataSource);//事务定义TransactionDefinition td = new DefaultTransactionDefinition();//事务状态TransactionStatus ts = ptm.getTransaction(td);Object ret = pjp.proceed(pjp.getArgs());ptm.commit(ts);return ret;}
}
 <bean id="txAdvice" class="com.aop.TxAdvice"><property name="dataSource" ref="dataSource"/></bean><aop:config><aop:pointcut id="pt" expression="execution(* *..taransfer(..))"/><aop:aspect ref="txAdvice"><aop:around method="transactionManager" pointcut-ref="pt"/></aop:aspect></aop:config>

6.声明式事务(XML)

tx配置----tx:advice

名称:tx:advice

类型:标签

归属:beans标签

作用:专用于声明事务通知

格式

<beans><tx:advice id="txAdvice" transaction-manager="txManager"></tx:advice>
</beans>

基本属性:

id :用于配置aop时指定通知器的id

transaction-manager :指定事务管理器bean

tx配置----tx:attributes

名称:tx:attributes

类型:标签

归属:tx:advice标签

作用:定义通知属性

格式

<tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes></tx:attributes>
</tx:advice>

基本属性:无

tx配置----tx:method

名称:tx:method

类型:标签

归属:tx:attribute标签

作用:设置具体的事务属性

格式

<tx:attributes><tx:method name="*" read-only="false" /><tx:method name="get*" read-only="true" />
</tx:attributes>

说明:通常事务属性会配置多个,包含一个读写的全事务属性,一个只读的查询类事务属性 

样例

开启tx命名空间 

<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/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttps://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttps://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!--定义事务管理的通知类--><tx:advice id="txAdvice" transaction-manager="txManager"><!--定义控制的事务--><tx:attributes><tx:method name="*" read-only="false"/><tx:method name="get*" read-only="true"/><tx:method name="find" read-only="true"/><tx:method name="transfer" read-only="false"/></tx:attributes></tx:advice><aop:config><aop:pointcut id="pt" expression="execution(* com.service.*Service.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/></aop:config>

 此时aop.TxAdvice就可以删除了

<!--<bean id="txAdvice" class="com.aop.TxAdvice"><property name="dataSource" ref="dataSource"/></bean><aop:config><aop:pointcut id="pt" expression="execution(* *..transfer(..))"/><aop:aspect ref="txAdvice"><aop:around method="transactionManager" pointcut-ref="pt"/></aop:aspect></aop:config>-->

此段也要删除

aop:advice与aop:advisor区别

aop:advice配置的通知类可以是普通java对象,不实现接口,也不使用继承关系

aop:advisor配置的通知类必须实现通知接口

        MethodBeforeAdvice

        AfterReturningAdvice

        ThrowsAdvice

        ……

7.tx:method属性

<tx:methodname="*"			待添加事务的方法名表达式(支持*号通配符)read-only="false"	设置事务的读写属性,true为只读,false为读写timeout="-1"		设置事务超时时长,单位秒isolation="DEFAULT"	设置事务隔离级别,该隔离级别设定是基于Spring的设定,非数据库端no-rollback-for="java.lang.ArithmeticException"	设置事务中不回滚的异常,多个异常间使用,分割rollback-for=""			设置事务中必回滚的异常,多个异常间使用,分割propagation="REQUIRED"	设置事务的传播行为/>

8.事务传播行为 

事务传播行为描述的是事务协调员对事务管理员所携带事务的处理态度

企业开发过程中,发现同属于同一个事务控制的各个业务中,如果某个业务与其他业务隔离度较高,拥有差异化的数据业务控制情况,通常使用事务传播行为对其进行控制

9.声明式事务(注解)

@Transactional

名称:@Transactional

类型:方法注解,类注解,接口注解

位置:方法定义上方,类定义上方,接口定义上方

作用:设置当前类/接口中所有方法或具体方法开启事务,并指定相关事务属性

范例

@Transactional(readOnly = false,timeout = -1,isolation = Isolation.DEFAULT,rollbackFor = {ArithmeticException.class, IOException.class},noRollbackFor = {},propagation = Propagation.REQUIRES_NEW
)

tx:annotation-driven

名称:tx:annotation-driven

类型:标签

归属:beans标签

作用:开启事务注解驱动,并指定对应的事务管理器

范例

<tx:annotation-driven transaction-manager="txManager"/>

样例

<?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/contexthttps://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttps://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttps://www.springframework.org/schema/aop/spring-aop.xsd"><context:property-placeholder location="classpath:*.properties"/><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driver}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><bean id="accountService" class="com.service.impl.AccountServiceImpl"><property name="accountDao" ref="accountDao"/><!--<property name="dataSource" ref="dataSource"/>--></bean><bean class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="typeAliasesPackage" value="com.domain"/></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.dao"/></bean><bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><tx:annotation-driven transaction-manager="txManager"/><!-- <tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><tx:method name="*" read-only="false"/><tx:method name="get*" read-only="true"/><tx:method name="find" read-only="true"/><tx:method name="transfer" read-only="false"/></tx:attributes></tx:advice><aop:config><aop:pointcut id="pt" expression="execution(* com.service.*Service.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/></aop:config>-->
</beans>

package com.service;import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Transactional(isolation = Isolation.DEFAULT)
public interface AccountService {/** 转账操作* outName  出账用户名* inName  入账用户名* money   转账金额*/@Transactional(readOnly = false,timeout = -1,isolation = Isolation.DEFAULT,rollbackFor = {},  //java.lang.ArithmeticException.class, IOException.classnoRollbackFor = {},propagation = Propagation.REQUIRED)public void transfer(String outName, String inName, Double money);
}

10.声明式事务(纯注解驱动)

名称:@EnableTransactionManagement

类型:类注解

位置:Spring注解配置类上方

作用:开启注解驱动,等同XML格式中的注解驱动

范例

@Configuration
@ComponentScan("com.lichee")
@PropertySource("classpath:jdbc.properties")
@Import({JDBCConfig.class,MyBatisConfig.class,TransactionManagerConfig.class})
@EnableTransactionManagement
public class SpringConfig {
}
public class TransactionManagerConfig {@Beanpublic PlatformTransactionManager getTransactionManager(@Autowired DataSource dataSource){return new DataSourceTransactionManager(dataSource);}
}

样例

package com.domain;public class Account {private Integer id;private String name;private Double money;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Double getMoney() {return money;}public void setMoney(Double money) {this.money = money;}@Overridepublic String toString() {return "Account{" +"id=" + id +", name='" + name + '\'' +", money=" + money +'}';}
}
package com.dao;import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;public interface AccountDao {@Update("update account set money = money + #{money} where name = #{name}")void inMoney(@Param("name") String name, @Param("money") Double money);@Update("update account set money = money - #{money} where name = #{name}")void outMoney(@Param("name") String name, @Param("money") Double money);}
package com.service;import org.springframework.transaction.annotation.Transactional;
@Transactional
public interface AccountService {public void transfer(String outName, String inName, Double money);
}
package com.service.impl;import com.dao.AccountDao;
import com.service.AccountService;
import org.apache.ibatis.annotations.Arg;
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;import java.io.IOException;
@Service("accountService")
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountDao accountDao;public void transfer(String outName, String inName, Double money) {accountDao.inMoney(outName,money);//int i = 1/0;accountDao.outMoney(inName,money);}
}
package com.config;import org.springframework.context.annotation.*;
import org.springframework.transaction.annotation.EnableTransactionManagement;@Configuration
@ComponentScan("com")
@PropertySource("classpath:jdbc.properties")
@Import({JDBCConfig.class,MyBatisConfig.class})
@EnableTransactionManagement
public class SpringConfig {
}
package com.config;import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;import javax.sql.DataSource;public class JDBCConfig {@Value("${jdbc.driver}")private String driver;@Value("${jdbc.url}")private String url;@Value("${jdbc.username}")private String userName;@Value("${jdbc.password}")private String password;@Bean("dataSource")public DataSource getDataSource(){DruidDataSource ds = new DruidDataSource();ds.setDriverClassName(driver);ds.setUrl(url);ds.setUsername(userName);ds.setPassword(password);return ds;}public PlatformTransactionManager gerTransactionManager(DataSource dataSource){return new DataSourceTransactionManager(dataSource);}
}
package com.config;import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;import javax.sql.DataSource;public class MyBatisConfig {@Beanpublic SqlSessionFactoryBean getSqlSessionFactoryBean(@Autowired DataSource dataSource){SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();ssfb.setTypeAliasesPackage("com.domain");ssfb.setDataSource(dataSource);return ssfb;}@Beanpublic MapperScannerConfigurer getMapperScannerConfigurer(){MapperScannerConfigurer msc = new MapperScannerConfigurer();msc.setBasePackage("com.dao");return msc;}
}

jdbc.properties 

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring_db?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=false
jdbc.username=root
jdbc.password=123456
package com.service;import com.config.SpringConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;//设定spring专用的类加载器
@RunWith(SpringJUnit4ClassRunner.class)
//设定加载的spring上下文对应的配置
@ContextConfiguration(classes = SpringConfig.class)
public class UserServiceTest {@Autowiredprivate AccountService accountService;@Testpublic void testTransfer(){accountService.transfer("Jock1","Jock2",100D);}
}

2.模板对象

1.Spring模板对象

TransactionTemplate

JdbcTemplate

RedisTemplate

RabbitTemplate

JmsTemplate

HibernateTemplate

RestTemplate

2.JdbcTemplate

提供标准的sql语句提供API

public void save(Account account) {String sql = "insert into account(name,money)values(?,?)";jdbcTemplate.update(sql,account.getName(),account.getMoney());
}

3.NamedParameterJdbcTemplate 

提供标准的sql语句提供API

public void save(Account account) {String sql = "insert into account(name,money)values(:name,:money)";Map pm = new HashMap();pm.put("name",account.getName());pm.put("money",account.getMoney());jdbcTemplate.update(sql,pm);
}

4.RedisTemplate

RedisTemplate对象结构

public void changeMoney(Integer id, Double money) {redisTemplate.opsForValue().set("account:id:"+id,money);
}
public Double findMondyById(Integer id) {Object money = redisTemplate.opsForValue().get("account:id:" + id);return new Double(money.toString());
}

3.事务底层原理解析

策略模式(Strategy Pattern)使用不同策略的对象实现不同的行为方式,策略对象的变化导致行为的变化

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

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C# WinForm AndtUI第三方库 Tree控件使用记录

环境搭建 1.在NuGet中搜索AndtUI并下载至C# .NetFramework WinForm项目。 2.添加Tree控件至窗体。 使用方法集合 1.添加节点、子节点 using AntdUI; private void UpdateTreeView() {Tree tvwTestnew Tree();TreeItem rootTreeItem;TreeItem subTreeItem;Dictionary<str…

pdf怎么转换成word?这三种方法简单实用

pdf怎么转换成word&#xff1f;在日常工作和学习中&#xff0c;我们经常会遇到需要将PDF文件转换成Word文档的情况。PDF文件虽然方便阅读&#xff0c;但编辑起来却相对困难。而Word文档则更加灵活&#xff0c;方便我们对内容进行修改和排版。那么&#xff0c;如何将PDF转换成Wo…

2024年【烟花爆竹经营单位主要负责人】考试报名及烟花爆竹经营单位主要负责人新版试题

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 烟花爆竹经营单位主要负责人考试报名是安全生产模拟考试一点通总题库中生成的一套烟花爆竹经营单位主要负责人新版试题&#xff0c;安全生产模拟考试一点通上烟花爆竹经营单位主要负责人作业手机同步练习。2024年【烟…

【优选算法】前缀和

前缀和思想其实就是一种简单的dp思想&#xff0c;也就是动态规划 什么时候用到前缀和&#xff1f;当要快速求出数组中某一个区间的和 前缀和模板 暴力解法 定义一个指针从左向右遍历&#xff0c;并且累加值即可&#xff0c;这里就不过多赘述&#xff0c;主要还是来看前缀和…

VR 全景模式OpenGL原理

VR 全景模式OpenGL原理 VR 全景模式原理 VR 全景模式原理将画面渲染到球面上&#xff0c;相当于从球心去观察内部球面&#xff0c;观察到的画面 360 度无死角&#xff0c;与普通播平面渲染的本质区别在渲染图像部分&#xff0c;画面渲染到一个矩形平面上&#xff0c;而全景需…

Linux--文件(2)-重定向和文件缓冲

命令行中的重定向符号 介绍和使用 在Linux的命令行中&#xff0c;重定向符号用于将命令的输入或输出重定向到文件或设备。 常见的重定向符号&#xff1a; 1.“>“符号&#xff1a;将命令的标准输出重定向到指定文件中&#xff0c;并覆盖原有的内容。 2.”>>“符号&a…

解决ipconfig不能使用的问题

问题所示&#xff1a;ipconfig不是内部或外部命令&#xff0c;也不是可运行的程序或批处理文件。 解决办法如下: 1.右击此电脑&#xff0c;点击属性设置&#xff1a; 2.点击高级系统设置 3.点击进入环境变量 4.在系统变量中进行设置&#xff0c;双击PATH进行配置 5.点击新建&am…

绝地求生 实事求是的优化 比增加更多玩法更有效

想必很多老玩家都知道&#xff0c;最初的绝地求生&#xff0c;那样才是最刺激 最好玩的 当然那时候大家都菜 也没有多少外挂 但是后面 为了迎合少部分玩家需求&#xff0c;而进行一些无所需要的改动&#xff0c;而增加一些繁琐而又关紧要的功能&#xff0c; 彻底失去了很多玩家…

【漏洞复现】大华DSS数字监控系统文件读取漏洞

Nx01 产品简介 大华DSS数字监控系统是一个在通用安防视频监控系统基础上设计开发的系统&#xff0c;除了具有普通安防视频监控系统的实时监视、云台操作、录像回放、报警处理、设备治理等功能外&#xff0c;更注重用户使用的便利性。 Nx02 漏洞描述 大华DSS数字监控系统downlo…

展馆设计中展示创造力和创新思维的关联

1、创新科技展示区 在科技展馆设计中可以设置创新科技展示区&#xff0c;展示科技在不同领域的创新应用。该区域可以展示各种前沿科技产品、研发成果和创新项目。通过展示科技的创新性和实用性&#xff0c;观众可以了解到科技如何推动人类创造力的发展和创新思维的实践。 2、创…

企业出海WAS安全自动化解决方案

随着企业出海的日益激烈&#xff0c;安全风险正在成为企业日益关注的问题之一&#xff0c;九河云携手AWS带来了使用Amazon WAF 与 Amazon Shield 的 CloudFront安全自动化。Aws WAF是一种web应用防火墙&#xff0c;可帮助保护客户的web应用程序或api免遭常规web漏洞的攻击。Aws…

微服务架构SpringCloud(2)

热点参数限流 注&#xff1a;热点参数限流默认是对Springmvc资源无效&#xff1b; 隔离和降级 1.开启feign.sentinel.enabletrue 2.FeignClient(fallbackFactory) 3.创建一个类并实现FallbackFactory接口 4.加入依赖 <!--添加Sentienl依赖--><dependency><gro…