04【Spring声明式事、传播行为、AOP事务控制】

news/2024/4/19 7:32:44/文章来源:https://blog.csdn.net/Bb15070047748/article/details/128104237

文章目录

  • 04【Spring声明式事、传播行为、AOP事务控制】
  • 一、Spring声明式事务
    • 1.1 回顾事务
      • 1.1.1 什么是事务?
      • 1.1.2 事务四大特性
      • 1.1.3 事务并发访问问题
      • 1.1.4 事务隔离级别
      • 1.1.5 MySQL事务相关命令
    • 1.2 Spring事务管理介绍
      • 1.2.1 编程式事务
      • 1.2.2 声明式事务
      • 1.2.3 Spring事务管理器
      • 1.2.4 事务传播行为
    • 1.3 Spring实现声明式事务
      • 1.3.1 案例准备
        • 1)SQL脚本:
        • 2)Maven依赖:
        • 3)jdbc.properties:
        • 4)实体类:
      • 1.3.2 事务通知XML配置
        • 1)Spring配置:
        • 2)业务类:
        • 3)测试类
      • 1.3.3 注解配置
        • 1)Spring配置
        • 2)业务类
        • 3)测试类

04【Spring声明式事、传播行为、AOP事务控制】

一、Spring声明式事务

1.1 回顾事务

1.1.1 什么是事务?

如果一个业务操作中多次访问了数据库,必须保证每条SQL语句都执行成功。如果其中有一条执行失败,所有已经执行过的代码必须回滚。回到没有执行前的状态。称为事务。要么所有的SQL语句全部执行成功,要么全部失败。

1.1.2 事务四大特性

事务特性含义
原子性(Atomicity)事务是工作的最小单元,整个工作单元要么全部执行成功,要么全部执行失败
一致性(Consistency)事务执行前与执行后,数据库中数据应该保持相同的状态。如:转账前总金额与转账后总金额相同。
隔离性(Isolation)事务与事务之间不能互相影响,必须保持隔离性。
持久性(Durability)如果事务执行成功,对数据库的操作是持久的。

1.1.3 事务并发访问问题

并发访问下事务产生的问题:

当同时有多个用户在访问同一张表中的记录,每个用户在访问的时候都是一个单独的事务。

事务在操作时的理想状态是:事务之间不应该相互影响,实际应用的时候会引发下面三种问题。应该尽量避免这些问题的发生。通过数据库本身的功能去避免,设置不同的隔离级别。

  • 脏读: 一个事务(用户)读取到了另一个事务没有提交的数据
  • 不可重复读:一个事务多次读取同一条记录,出现读取数据不一致的情况。一般因为另一个事务更新了这条记录而引发的。
  • 幻读:在一次事务中,多次读取到的条数不一致

1.1.4 事务隔离级别

级别名字隔离级别脏读不可重复读幻读数据库默认隔离级别
1读未提交read uncommitted
2读已提交read committedOracle和SQL Server
3可重复读repeatable readMySQL
4串行化serializable
  • 1)Read uncommitted (读未提交): 简称RU隔离级别,所有事务中的并发访问问题都会发生,读取的是其他事务没有提交的数据

  • 2)Read committed (读已提交):简称RC隔离级别,会引发不可重复读和幻读的问题,读取的永远是其他事务提交的数据

  • 3)Repeatable read (可重复读):简称RR隔离级别,有可能会引发幻读的问题,一次事务读取到的同一行数据,永远是一样

  • 4)Serializable (串行化): 可以避免所有事务产生的并发访问的问题 效率及其低下

1.1.5 MySQL事务相关命令

  • 测试表:
drop table if exists account;-- 创建数据表  
CREATE TABLE account (  id INT PRIMARY KEY AUTO_INCREMENT,  name VARCHAR(10),  money DOUBLE  
);  -- 添加数据  
INSERT INTO account (name, money) VALUES ('a', 1000), ('b', 1000);
  • 查询事务隔离级别:
select @@tx_isolation;
  • 设置事务隔离级别:
set global transaction isolation level 四种隔离;set global transaction isolation level read uncommitted;
set global transaction isolation level read committed;
set global transaction isolation level repeatable read;
set global transaction isolation level serializable;

需要重启客户端会话

  • 开启事务:
start transaction;
或者
begin;
  • 提交事务:
commit;
  • 回滚事务:
rollback;

1.2 Spring事务管理介绍

1.2.1 编程式事务

  • 什么是编程式事务?

编程式事务简单的来说就是采用编程的方式来管理事务,编程式事务需要将事务管理的代码写入到业务方法中,相对于核心业务而言,事务管理的代码显然属于非核心业务对核心业务代码的侵入性太大;而且如果多个模块都使用同样模式的代码进行事务管理,显然会造成较大程度的代码冗余

我们之前使用的JDBC API来操作事务就是编程式事务;

1.2.2 声明式事务

  • 什么是声明式事务?

声明式事务以声明的方式来实现事务管理,其本质是对方法前后进行拦截,然后在目标方法开始之前创建或者加入一个事务,在执行完目标方法之后根据执行情况提交或者回滚事务。

声明式事务简单的来说就是通过一些表达式声明(拦截)一堆需要被事务管理的方法,然后被声明(拦截)的方法通过AOP的方式进行事务管理(执行目标方法之前开启事务,执行目标方法之后提交或者回滚事务)

显然声明式事务管理要优于编程式事务管理:它将事务管理代码从业务方法中分离出来,这正是Spring倡导的非侵入式的开发方式。声明式事务管理使业务代码不受干扰;一个普通的对象,只要加上注解就可以获得完全的事务支持。

声明式事务唯一不足地方是,它的最细粒度只能作用到方法级别,无法做到像编程式事务那样可以作用到代码块级别。但是即便有这样的需求,也存在很多变通的方法,比如,可以将需要进行事务管理的代码块独立为方法等等。

1.2.3 Spring事务管理器

Spring从不同的事务管理API中抽象出了一整套事务管理机制,让事务管理代码从特定的事务技术中独立出来。开发人员通过配置的方式进行事务管理,而不必了解其底层是如何实现的。

Spring所有的事务管理策略类都继承自org.springframework.transaction.PlatformTransactionManager接口。

它为事务管理封装了一组独立于技术的方法。无论使用Spring的哪种事务管理策略(编程式或声明式),事务管理器都是必须的。

  • 事务管理器主要的实现:
    • DataSourceTransactionManager:使用Spring JDBC 或 Mybatis 等基于DataSource数据源的持久化技术时,使用 该事务管理器
    • JpaTransactionManager:使用JPA时采用的事务管理器
    • JtaTransactionManager:具有多个数据源的全局事务使用该事务管理器
    • JdoTransactionManager:使用JDO进行持久化时 ,使用该事务管理器
    • HibernateTransactionManager:使用Hibernate进行持久化时,使用该事务管理器

1.2.4 事务传播行为

当事务方法被另一个事务方法调用时,必须指定事务应该如何传播。

例如:方法可能继续在现有事务中运行,也可能开启一个新事务,并在自己的事务中运行。事务的传播行为可以由传播属性指定。Spring定义了7种类传播行为,在org.springframework.transaction.TransactionDefinition类中被定义。

静态常量说明
PROPAGATION_REQUIRED如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中。这是最常见的选择,也是Spring的默认值
PROPAGATION_SUPPORTS支持当前事务,如果当前没有事务,就以非事务方式执行。
PROPAGATION_MANDATORY使用当前的事务,如果当前没有事务,就抛出异常。
PROPAGATION_REQUIRES_NEW新建事务,如果当前存在事务,把当前事务挂起。
PROPAGATION_NOT_SUPPORTED以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。
PROPAGATION_NEVER以非事务方式执行,如果当前存在事务,则抛出异常。
PROPAGATION_NESTED如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则执行与PROPAGATION_REQUIRED类似的操作。

TransactionDefinition类中不仅定义了事务的传播行为,也定义了很多事务的隔离级别:

静态常量说明
ISOLATION_DEFAULT使用数据库默认的隔离级别,Spring默认值
ISOLATION_READ_UNCOMMITTED读未提交
ISOLATION_READ_COMMITTED读已提交
ISOLATION_REPEATABLE_READ可重复读
ISOLATION_SERIALIZABLE串行化

1.3 Spring实现声明式事务

1.3.1 案例准备

1)SQL脚本:

drop database if exists spring;create database spring;use spring;-- 创建数据表  
CREATE TABLE account (  id INT PRIMARY KEY AUTO_INCREMENT,  name VARCHAR(10),  money DOUBLE  
);  -- 添加数据  
INSERT INTO account (name, money) VALUES ('a', 1000), ('b', 1000);

2)Maven依赖:

<?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.dfbz</groupId><artifactId>01_Spring</artifactId><version>1.0-SNAPSHOT</version><dependencies><!--spring基本环境依赖--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.9.RELEASE</version></dependency><!--spring对jdbc的支持(DataSourceTransaction)--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.2.9.RELEASE</version></dependency><!--spring对事物的支持--><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>5.2.9.RELEASE</version></dependency><!--spring对切面AspectsJ的支持--><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>5.2.9.RELEASE</version></dependency><!--spring对junit的整合--><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.48</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.1</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.18</version></dependency></dependencies></project>

3)jdbc.properties:

jdbc.username=root
jdbc.password=admin
jdbc.url=jdbc:mysql:///spring
jdbc.driverClassName=com.mysql.jdbc.Driver

4)实体类:

package com.dfbz.entity;import lombok.Data;/*** @author lscl* @version 1.0* @intro:*/
@Data
public class Account {private Integer id;private String name;private Double money;
}

1.3.2 事务通知XML配置

1)Spring配置:

<?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:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"><!--组件扫描--><context:component-scan base-package="com.dfbz" /><!--加载配置文件--><context:property-placeholder location="classpath:jdbc.properties"/><!--druid数据源--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property><property name="url" value="${jdbc.url}"></property><property name="driverClassName" value="${jdbc.driverClassName}"></property></bean><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean><!-- 配置事务管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!--引用数据源--><property name="dataSource" ref="dataSource"/></bean><!--配置事务通知--><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!--isolation:事务隔离级别DEFAULT:使用数据库默认的隔离级别(默认值)READ_UNCOMMITTED:读未提交READ_COMMITTED:读已提交REPEATABLE_READ:可重复读SERIALIZABLE:串行化propagation: 事务传播行为REQUIRED:必须要有事务,如果已经存在事务,则加入到这个事务中,如果没有事务则创建一个新的事务SUPPORTS:支持当前事务,如果调用这个方法之前没有事务则不会开启新的事务MANDATORY:必须存在事务,如果调用此方法之前没有事务,就抛出异常REQUIRES_NEW:新建事务,如果调用此方法之前就已经开启过事务,则将之前的事务挂起NOT_SUPPORTED:非事务方式,如果调用此方法之前就存在事务,则挂起事务NEVER:非事务方式运行,如果调用此方法之前存在事务,则抛出异常NESTED:如果存在事务,则嵌套在事务内执行,如果没有事务则与REQUIRED保存一致read-only: 是否只读true: 只读false:非只读(默认值)timeout: 方法执行超时时间,默认值为-1,代表永不超时,单位为秒rollback-for: 指定特定的异常才回滚(默认情况下,任何的运行时异常事务都会回滚,但编译时异常都不会进行回滚),该配置针对于编译时异常;可以写多个,以逗号隔开no-rollback-for: 指定一个特定的异常事务不回滚,可以写多个,以逗号隔开-->
<!--            <tx:method name="query*" isolation="DEFAULT"propagation="REQUIRED" read-only="true" timeout="3"rollback-for="java.lang.NullPointerException,java.lang.ClassCastException"no-rollback-for="java.lang.ArithmeticException"  />-->
<!--            <tx:method name="query*" read-only="true"/>-->
<!--            <tx:method name="select*" read-only="true"/>-->
<!--            <tx:method name="query*" read-only="true"/>-->
<!--            <tx:method name="save*" read-only="true"/>-->
<!--            <tx:method name="insert*" />-->
<!--            <tx:method name="add*" />-->
<!--            <tx:method name="update*" />-->
<!--            <tx:method name="modify*" />-->
<!--            <tx:method name="delete*" />-->
<!--            <tx:method name="remove*" />--><!--出现ArithmeticException异常不回滚--><tx:method name="transfer" no-rollback-for="java.lang.ArithmeticException"/></tx:attributes></tx:advice><!--配置切面--><aop:config><!--定义切入点--><aop:pointcut id="myPoint" expression="execution(* com.dfbz.service.AccountService.*(..))"/><!--将通知应用到切入点上(织入)--><aop:advisor advice-ref="txAdvice" pointcut-ref="myPoint"></aop:advisor></aop:config>
</beans>

**默认情况下,任何的运行时异常事务都会回滚,但编译时异常都不会进行回滚;**我们可以通过一些配置来调整

  • no-rollback-for:指定什么异常不回滚,可以写多个,以逗号隔开;

  • rollback-for:该配置针对于编译时异常;可以写多个,以逗号隔开;

上述两个参数在指定异常时,如果指定某个异常的父类,包括这个异常的所有子类异常都会回滚;

如:no-rollback-for指定的参数是Exception则代表Java中的任何异常都不回滚,

rollback-for指定的参数是Exception则Java中任何的异常都回滚;

2)业务类:

package com.dfbz.service;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;/*** @author lscl* @version 1.0* @intro:*/
@Service
public class AccountService {@Autowiredprivate JdbcTemplate jdbcTemplate;/*** @param str     : 谁要转账* @param target: 转账给谁* @param flag:   模拟异常 true:出现异常 false:不出现异常*/public void transfer(String str, String target, Boolean flag) {jdbcTemplate.update("update account set money=money-500 where name=?", str);if (flag) {// 模拟异常int i = 1 / 0;}jdbcTemplate.update("update account set money=money+500 where name=?", target);}/**** @param id*/public void findById(Integer id) {Account account = jdbcTemplate.queryForObject("select * from account where id=?",new BeanPropertyRowMapper<>(Account.class),id);}
}

3)测试类

package com.dfbz.test;import com.dfbz.service.AccountService;
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.SpringRunner;/*** @author lscl* @version 1.0* @intro:*/
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath:spring.xml")
public class Demo01 {@Autowiredprivate AccountService accountService;@Testpublic void test1(){accountService.transfer("a","b",false);}
}

1.3.3 注解配置

1)Spring配置

<?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:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"><!--组件扫描--><context:component-scan base-package="com.dfbz" /><!--加载配置文件--><context:property-placeholder location="classpath:jdbc.properties"/><!--druid数据源--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property><property name="url" value="${jdbc.url}"></property><property name="driverClassName" value="${jdbc.driverClassName}"></property></bean><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean><!-- 配置事务管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!--引用数据源--><property name="dataSource" ref="dataSource"/></bean><!--开启事务注解驱动transaction-manager: 指定事务管理的名称,默认为transactionManager--><tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven></beans>

2)业务类

package com.dfbz.service;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;/*** @author lscl* @version 1.0* @intro:*/
@Service
public class AccountService {@Autowiredprivate JdbcTemplate jdbcTemplate;/*** @param str     : 谁要转账* @param target: 转账给谁* @param flag:   模拟异常 true:出现异常 false:不出现异常*/
/*    @Transactional(transactionManager = "transactionManager",              // 事务管理器的名称propagation = Propagation.REQUIRED,                     // 传播行为isolation = Isolation.DEFAULT,                          // 隔离级别timeout = 3000,                                         // 超时时间readOnly = false,                                       // 是否只读rollbackFor = {MyException.class},       				// 出现该异常回滚noRollbackFor = {ArithmeticException.class}             // 出现指定异常不回滚)    */@Transactional              // 使用注解方式管理事务public void transfer(String str, String target, Boolean flag) {jdbcTemplate.update("update account set money=money-500 where name=?", str);if (flag) {// 模拟异常int i = 1 / 0;}jdbcTemplate.update("update account set money=money+500 where name=?", target);}
}

3)测试类

package com.dfbz.test;import com.dfbz.service.AccountService;
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.SpringRunner;/*** @author lscl* @version 1.0* @intro:*/
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath:spring2.xml")
public class Demo02 {@Autowiredprivate AccountService accountService;@Testpublic void test1(){accountService.transfer("a","b",false);}
}

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

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

相关文章

【车载开发系列】UDS诊断---电控单元复位 ($0x11)

【车载开发系列】UDS诊断—电控单元复位&#xff08;$0x11&#xff09; UDS诊断---电控单元复位&#xff08;$0x11&#xff09;【车载开发系列】UDS诊断---电控单元复位&#xff08;$0x11&#xff09;一.概念定义二.应用场景三.报文格式1&#xff09;请求2&#xff09;肯定响应…

Spark 3.0 - 8.ML Pipeline 之决策树原理与实战

目录 一.引言 二.决策树基础-信息熵 三.决策树的算法基础 - ID3 算法 四.ML 中决策树的构建 1.信息增益计算 2.连续属性划分 五.ML 决策树实战 1.Libsvm 数据与加载 2.StringIndexer 3.VectorIndexer 4.构建决策树与 Pipeline 5.测试与评估 6.获取决策树 六.总结…

基于PHP+MySQL企业网络推广平台系统的设计与实现

企业网络推广平台系统具有很强的信息指导性特征,采用PHP开发企业网络推广平台系统 给web带来了全新的动态效果,具有更加灵活和方便的交互性。在Internet中实现数据检索越来越容易,可以及时、全面地收集、存储大量的企业资源信息以及进行发布、浏览、搜索相关的信息。让企业、个…

C++ Reference: Standard C++ Library reference: Containers: list: list: cend

C官网参考链接&#xff1a;https://cplusplus.com/reference/list/list/cend/ 公有成员函数 <list> std::list::cend const_iterator cend() const noexcept; 返回结束的常量迭代器 返回一个指向容器结束后元素的const_iterator。 const_iterator是指向const内容的迭代…

Spring Boot FailureAnalyzer 应用场景

Spring Boot 自定义FailureAnalyzer 今天在学习Spring Boot 源码的过程中&#xff0c;在spring.factories 文件中无意中发现了FailureAnalyzer 这个接口。由于之前没有接触过&#xff0c;今天来学习一下 FailureAnalyzer 接口的作用。 在学习FailureAnalyzer之前, 我们先看以…

TMA三均线股票期货高频交易策略的R语言实现

趋势交易策略是至今应用最广泛以及最重要的投资策略之一&#xff0c;它的研究手段种类繁多&#xff0c;所运用的分析工具也纷繁复杂&#xff0c;其特长在于捕捉市场运动的大方向。股指期货市场瞬息万变&#xff0c;结合趋势分析方法&#xff0c;量化投资策略能够得到更有效的应…

Discourse 的左侧边栏可以修改吗

在默认的 Discourse 配置中&#xff0c;我们左侧的边栏可以根据自己的要求进行修改吗&#xff1f; 解决办法 针对自己登录的用户&#xff0c;你是可以自己调整左侧边栏的配置。 单击右上角你的个人头像&#xff0c;然后选择属性。 在切换的界面中&#xff0c;选择属性。 在出…

校园论坛(Java)——环境配置篇

校园论坛&#xff08;Java&#xff09;——环境配置篇 文章目录校园论坛&#xff08;Java&#xff09;——环境配置篇1、写在前面2、新建Maven项目2.1 引入相关依赖2.2 配置Tomcat环境3、项目发布测试4、项目代码5、参考资料1、写在前面 Windows版本&#xff1a;Windows10JDK版…

Python数据库编程之关系数据库API规范

Python关系数据库API规范 对于关系数据库的访问&#xff0c;Python社区已经制定出一个标准&#xff0c;称为Python Database API Specification。Mysql&#xff0c;Oracal等特定数据库模块遵从这一规范&#xff0c;而且可以添加更多特性。 高级数据库API定义了一组用于连接数…

YOLO V3 详解

YOLO V3 论文链接&#xff1a;YOLOv3: An Incremental Improvement 主要改进 Anchor: 9个大小的anchor&#xff0c;每个尺度分配3个anchor。Backbone改为Darknet-53, 引入了残差模块。引入了FPN&#xff0c;可以进行多个尺度的训练&#xff0c;同时对于小目标的检测有了一定…

R语言生存分析可视化分析

生存分析指的是一系列用来探究所感兴趣的事件的发生的时间的统计方法。 生存分析被用于各种领域&#xff0c;例如&#xff1a; 癌症研究为患者生存时间分析&#xff0c; “事件历史分析”的社会学 在工程的“故障时间分析”。 在癌症研究中&#xff0c;典型的研究问题如下…

Linux redict 输入输出重定向 详细使用方法 文件描述符

Linux redict 重定向 Linux 重定向 在 Linux 系统中&#xff0c;我们需要输入和输出让系统与外部进行交互&#xff0c;比如在我们使用鼠标、键盘等输入设备时其实就是通过输入的方式让数据进行系统中。而系统输出一般就会打印在显示器上、刻录光盘等等。而我们要讲的重定向也…

(二)DepthAI-python相关接口:OAK Pipeline

消息快播&#xff1a;OpenCV众筹了一款ROS2机器人rae&#xff0c;开源、功能强、上手简单。来瞅瞅~ 编辑&#xff1a;OAK中国 首发&#xff1a;oakchina.cn 喜欢的话&#xff0c;请多多&#x1f44d;⭐️✍ 内容可能会不定期更新&#xff0c;官网内容都是最新的&#xff0c;请查…

Meta-learning

基本理解 meta learning翻译为元学习&#xff0c;也可以被认为为learn to learn 元学习与传统机器学习的不同在哪里&#xff1f; 元学习与传统机器学习&#xff0c; 这里举个通俗的例子&#xff0c;拿来给大家分享&#xff1f; 把训练算法类比成学生在学校学习&#xff0c;传…

【华为上机真题 2022】字符串分隔

&#x1f388; 作者&#xff1a;Linux猿 &#x1f388; 简介&#xff1a;CSDN博客专家&#x1f3c6;&#xff0c;华为云享专家&#x1f3c6;&#xff0c;Linux、C/C、云计算、物联网、面试、刷题、算法尽管咨询我&#xff0c;关注我&#xff0c;有问题私聊&#xff01; &…

[附源码]计算机毕业设计springboot环境保护宣传网站

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

后端存储实战课总结(上)

创建和更新订单 表设计 最少应该有以下几张表&#xff1a; 订单主表&#xff1a;保存订单基本信息订单商品表&#xff1a;保存订单中的商品信息订单支付表&#xff1a;保存订单支付和退款信息订单优惠表&#xff1a;保存订单的优惠信息 订单主表和字表是一对多关系&#xf…

1.1 统计学习方法的定义与分类

统计学习方法的定义与分类统计学习的概念统计学习的定义统计学习运用到的领域统计学习的步骤统计学习的分类统计学习的概念 统计学习的定义 统计学习 (Statistical Machine Learning) 是关于计算机基于数据构建概率统计模型并运用模型对数据进行预测与分析的一门学科。 以计…

第五站:操作符(终幕)(一些经典的题目)

目录 一、分析下面的代码 二、统计二进制中1的个数 解一&#xff1a;&#xff08;求出每一个二进制位&#xff0c;来统计1的个数&#xff09; 解二&#xff1a;&#xff08;利用左我们移或右移操作符和按位与&#xff09; 解三&#xff1a;&#xff08;效率最高的解法&…