三天学会阿里分布式事务框架Seata-SpringCloud Alibaba分布式基础案例搭建

锋哥原创的分布式事务框架Seata视频教程:

实战阿里分布式事务框架Seata视频教程(无废话,通俗易懂版)_哔哩哔哩_bilibili实战阿里分布式事务框架Seata视频教程(无废话,通俗易懂版)共计10条视频,包括:1 阿里分布式事务框架Seata简介、2 分布式事务简介、3 SpringCloud Alibaba分布式基础案例搭建等,UP主更多精彩视频,请关注UP账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV1Uf4y1579F/我们模拟一个简单下单业务,客户端调用rest对外服务,rest服务再调用订单服务实现创建订单和账户服务实现账户扣钱操作,最终来完整下单业务;

2.1 案例架构设计

所有服务都注册到nacos中,方便feign远程调用;订单服务,账户服务各自有独立数据库;架构设计如下图:

整体项目结构如下图:

seatatest是父项目,主要是做一些依赖管理,依赖版本管理,管理所有子module项目;

seata-common子项目,主要是引入其他子项目需要的公共依赖,以及公共实体,工具类,配置类的统一封装;

seata-order子项目,主要提供订单服务,生成订单;

seata-account子项目,主要提供账户服务,根据订单扣钱操作;

seata-web子项目,主要处理客户端下单请求,feign远程调用order,和account服务接口,最终完成下单处理;

2.2 数据库设计

我们新建两个数据库,分别是db_order(订单数据库),db_account(账户数据库),

db_order数据库里面新建表t_order订单表:

CREATE TABLE `t_order` (`id` int(11) NOT NULL AUTO_INCREMENT,`orderNo` varchar(100) DEFAULT NULL,`userId` int(11) DEFAULT NULL,`count` int(11) DEFAULT NULL,`amount` int(11) DEFAULT NULL,`remark` varchar(100) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8

db_account数据库里面新建表t_account用户账户表:

CREATE TABLE `t_account` (`id` int(11) NOT NULL AUTO_INCREMENT,`userId` int(11) DEFAULT NULL,`balance` int(11) DEFAULT NULL,`remark` varchar(100) DEFAULT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8

插入数据:

insert into `t_account` (`id`, `userId`, `balance`, `remark`) values('1','1','2000','jack的账户');
insert into `t_account` (`id`, `userId`, `balance`, `remark`) values('2','2','1000','marry的账户');

2.3 seatatest父项目搭建

seatatest是父项目,主要是做一些依赖管理,依赖版本管理,管理所有子module项目;

注意,它的packaging类型是pom

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.java1234</groupId><artifactId>seatatest</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><module>seata-common</module><module>seata-order</module><module>seata-account</module><module>seata-web</module></modules><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><druid.version>1.1.10</druid.version><spring-cloud.version>Hoxton.SR8</spring-cloud.version><springboot.version>2.3.2.RELEASE</springboot.version><springcloudalibaba.version>2.2.4.RELEASE</springcloudalibaba.version><fastjson.version>1.2.35</fastjson.version><commons-lang3.version>3.6</commons-lang3.version><seata-common.version>1.0-SNAPSHOT</seata-common.version><mybatis.version>2.1.0</mybatis.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${springboot.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${springcloudalibaba.version}</version><type>pom</type><scope>import</scope></dependency><!-- 连接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>${druid.version}</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>${fastjson.version}</version></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>${commons-lang3.version}</version></dependency><dependency><groupId>com.java1234</groupId><artifactId>seata-common</artifactId><version>${seata-common.version}</version></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>${mybatis.version}</version></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

2.4 seata-common子项目搭建

seata-common子项目,主要是引入其他子项目需要的公共依赖,以及公共实体,工具类,配置类的统一封装;

项目结构:

<?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"><parent><artifactId>seatatest</artifactId><groupId>com.java1234</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>seata-common</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId></dependency><!-- spring boot redis 缓存引入 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!-- lettuce pool 缓存连接池 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-pool2</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId></dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId></dependency></dependencies></project>

订单实体Order

package com.java1234.entity;/**订单表实体* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-13 10:26*/
public class Order {private Integer id; // 编号private String orderNo; // 订单号private Integer userId; // 用户编号private Integer count; // 购买数量private Integer amount; // 购买金额private String remark; // 备注public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getOrderNo() {return orderNo;}public void setOrderNo(String orderNo) {this.orderNo = orderNo;}public Integer getUserId() {return userId;}public void setUserId(Integer userId) {this.userId = userId;}public Integer getCount() {return count;}public void setCount(Integer count) {this.count = count;}public Integer getAmount() {return amount;}public void setAmount(Integer amount) {this.amount = amount;}public String getRemark() {return remark;}public void setRemark(String remark) {this.remark = remark;}
}

账户实体Account

package com.java1234.entity;/*** 用户账户表* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-13 10:36*/
public class Account {private Integer id; // 编号private Integer userId; // 用户编号private Integer balance; // 账户余额private String remark; // 备注public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public Integer getUserId() {return userId;}public void setUserId(Integer userId) {this.userId = userId;}public Integer getBalance() {return balance;}public void setBalance(Integer balance) {this.balance = balance;}public String getRemark() {return remark;}public void setRemark(String remark) {this.remark = remark;}
}

2.5 seata-order子项目搭建

seata-order子项目,主要提供订单服务,生成订单;

项目结构:

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"><parent><artifactId>seatatest</artifactId><groupId>com.java1234</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>seata-order</artifactId><dependencies><dependency><groupId>com.java1234</groupId><artifactId>seata-common</artifactId></dependency></dependencies></project>

application.yml

server:port: 8081servlet:context-path: /spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/db_order?serverTimezone=Asia/Shanghaiusername: rootpassword: 123456cloud:nacos:discovery:server-addr: 127.0.0.1:8848application:name: seata-ordermybatis:mapper-locations: classpath:mybatis/mapper/*.xml

启动类OrderApplication

package com.java1234;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@SpringBootApplication
@MapperScan("com.java1234.mapper")
@EnableDiscoveryClient
public class OrderApplication {public static void main(String[] args) {SpringApplication.run(OrderApplication.class, args);}}

OrderMapper.xml

<?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.java1234.mapper.OrderMapper"><select id="createOrder" parameterType="com.java1234.entity.Order" >insert into t_order values(null,#{orderNo},#{userId},#{count},#{amount},#{remark})</select>
</mapper>

OrderMapper接口:

package com.java1234.mapper;import com.java1234.entity.Order;/*** @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-13 10:43*/
public interface OrderMapper {/*** 创建订单* @param order*/void createOrder(Order order);}

OrderService接口:

package com.java1234.service;import com.java1234.entity.Order;/*** 订单service接口* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-14 11:00*/
public interface OrderService {/*** 创建订单* @param order*/void createOrder(Order order);}

OrderServiceImpl实现类:

package com.java1234.service.impl;import com.java1234.entity.Order;
import com.java1234.mapper.OrderMapper;
import com.java1234.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;/*** @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-14 11:02*/
@Service("orderService")
public class OrderServiceImpl implements OrderService {@Autowiredprivate OrderMapper orderMapper;@Overridepublic void createOrder(Order order) {orderMapper.createOrder(order);}
}

OrderController

package com.java1234.controller;import com.java1234.entity.Order;
import com.java1234.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.UUID;/*** @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-14 11:13*/
@RestController
@RequestMapping("/seata")
public class OrderController {@Autowiredprivate OrderService orderService;/*** 创建订单* @param order* @return*/@PostMapping("/createOrder")public boolean createOrder(@RequestBody Order order){System.out.println("order:"+order);order.setOrderNo(UUID.randomUUID().toString());  // 生成订单IDorderService.createOrder(order);return true;}
}

2.6 seata-account子项目搭建

seata-account子项目,主要提供账户服务,根据订单扣钱操作;

项目结构:

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"><parent><artifactId>seatatest</artifactId><groupId>com.java1234</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>seata-account</artifactId><dependencies><dependency><groupId>com.java1234</groupId><artifactId>seata-common</artifactId></dependency></dependencies></project>

application.yml

server:port: 8082servlet:context-path: /spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/db_account?serverTimezone=Asia/Shanghaiusername: rootpassword: 123456cloud:nacos:discovery:server-addr: 127.0.0.1:8848application:name: seata-accountmybatis:mapper-locations: classpath:mybatis/mapper/*.xml

AccountApplication启动类:

package com.java1234;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@SpringBootApplication
@MapperScan("com.java1234.mapper")
@EnableDiscoveryClient
public class AccountApplication {public static void main(String[] args) {SpringApplication.run(AccountApplication.class, args);}}

AccountMapper.xml

<?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.java1234.mapper.AccountMapper"><select id="decrease" parameterType="Map" >UPDATE t_account SET balance=balance-#{amount} WHERE userId=#{userId}</select>
</mapper>

AccountMapper接口:

package com.java1234.mapper;import java.util.Map;/*** 账户Mapper接口* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-13 10:43*/
public interface AccountMapper {/*** 账户扣钱*/void decrease(Map map);}

AccountService接口:

package com.java1234.service;import java.util.Map;/*** 账户service接口* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-15 12:58*/
public interface AccountService {/*** 账户扣钱*/void decrease(Map map);
}

`AccountServiceImpl`接口实现类:

package com.java1234.service.impl;import com.java1234.mapper.AccountMapper;
import com.java1234.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.Map;/*** 账户Service实现类* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-15 13:00*/
@Service("accountService")
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountMapper accountMapper;@Overridepublic void decrease(Map map) {accountMapper.decrease(map);}
}

AccountController

package com.java1234.controller;import com.java1234.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;/*** 账户Controller* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-15 13:06*/
@RestController
@RequestMapping("/account")
public class AccountController {@Autowiredprivate AccountService accountService;/*** 给指定用户账户扣钱* @param amount* @param userId* @return*/@PostMapping("/decrease")public boolean decrease(@RequestParam("amount")Integer amount, @RequestParam("userId")Integer userId){System.out.println("amount:"+amount+",userId:"+userId);Map<String,Object> map=new HashMap<>();map.put("amount",amount);map.put("userId",userId);accountService.decrease(map);return true;}}

2.7 seata-web子项目搭建

seata-web子项目,主要处理客户端下单请求,feign远程调用order,和account服务接口,最终完成下单处理;

项目结构:

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"><parent><artifactId>seatatest</artifactId><groupId>com.java1234</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>seata-web</artifactId><dependencies><dependency><groupId>com.java1234</groupId><artifactId>seata-common</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency></dependencies></project>

application.yml

server:port: 80servlet:context-path: /spring:cloud:nacos:discovery:server-addr: 127.0.0.1:8848application:name: seata-web

WebApplication

package com.java1234;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableFeignClients(basePackages = "com.java1234.feign")
@EnableDiscoveryClient
public class WebApplication {public static void main(String[] args) {SpringApplication.run(WebApplication.class, args);}}

OrderFeignService

package com.java1234.feign;import com.java1234.entity.Order;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;/*** 订单接口feign远程调用* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-16 10:55*/
@FeignClient("seata-order")
public interface OrderFeignService {/*** 创建订单* @param order* @return*/@PostMapping("/seata/createOrder")public boolean createOrder(@RequestBody Order order);}

AccountFeignService

package com.java1234.feign;import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;/*** 账号接口feign远程调用* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-16 10:55*/
@FeignClient("seata-account")
public interface AccountFeignService {/*** 账号扣钱* @param amount* @param userId* @return*/@PostMapping("/account/decrease")public boolean decrease(@RequestParam("amount")Integer amount, @RequestParam("userId")Integer userId);}

WebController

package com.java1234.controller;import com.java1234.entity.Order;
import com.java1234.feign.AccountFeignService;
import com.java1234.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;/*** web-rest接口* @author java1234_小锋* @site www.java1234.com* @company 南通小锋网络科技有限公司* @create 2021-07-15 16:32*/
@RestController
public class WebController {@Autowiredprivate OrderFeignService orderFeignService;@Autowiredprivate AccountFeignService  accountFeignService;/*** 下单 1,创建订单 2,账户扣钱* @param order* @return*/@PostMapping("/shopping")public boolean shopping(Order order){orderFeignService.createOrder(order); // 创建订单accountFeignService.decrease(order.getAmount(),order.getUserId()); // 账户扣钱return true;}}

2.8 postman测试

首先启动Nacos服务注册中心:

项目启动:

Nacos控制台:

服务注册成功!

测试接口:http://localhost/shopping

接口测试OK:

订单表生成订单:

账户表id=1的jack账户成功扣减180元;

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

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

相关文章

日志到filebeat-->logstash-->elastic-->kibana

1、日志到filebeat。 cat /etc/filebeat/filebeat.yml filebeat.inputs: - type: syslog format: rfc3164 protocol.udp: host: "0.0.0.0:514" output.logstash: hosts: ["localhost:5044"] 验证方式: tcpdump -i 网卡名称 udp port 514 2、…

瑞吉苍穹外卖如何拓展?已经经过不同公司多轮面试。项目中会问到哪些问题?以及问题如何解决?

别催了&#xff0c;别催了&#xff0c;先收藏吧。 作者大大正在加班加点完成。 文章会尽快发布&#xff0c;关注收藏&#xff0c;尽请期待。 想要加入并查阅作者的知识库可以联系作者 不要白嫖&#xff0c;通过后&#xff0c;附上关注和收藏截图。 已有众多小伙伴加入 目前…

QtCreator报Failed to parse qmlimportscanner output解决

错误如下: 定位错误位置 增加错误信息打印 打印执行命令 执行打印输出的命令,成功返回JSON 但输出的JSON对象不是json格式,而是命令 增加$$成功输出JSON 使用QtCreator12编译一次后,再使用QtCreator13成功编译通过,问题解决

初学者如何使用QT新建一个包含UI界面的C++项目

文章目录 一、下载并安装QT51、下载安装包2、注册/登录账号3、安装qt6 二、新建QT Widget项目1、新建项目并且运行2、易错点&#xff1a;可能运行成功得到UI界面但是会报错&#xff08;原因是使用了中文路径&#xff09; 一、下载并安装QT5 1、下载安装包 进入下载网址 Windo…

面试经典150题【41-50】

文章目录 面试经典150题【41-50】49.字母异位词分组1. 两数之和202.快乐数219. 存在重复元素II128.最长连续序列228. 汇总区间56.合并区间&#xff08;华为面试题&#xff09;57.插入区间452.用最少的箭引爆气球20.有效的括号 面试经典150题【41-50】 49.字母异位词分组 用这种…

TensorBoard的使用,add_image()的使用。

在TensorBoard中&#xff0c;add_image()函数用于将图像数据添加到可视化中。它可以用于显示模型输入、输出、中间特征图等图像数据&#xff0c;以帮助开发者理解模型的运行情况。 add_image()的用法&#xff1a; 使用ctrl点击add_image() 注意&#xff1a;图片类型要求为 t…

机器学习笔记 YOLOv9模型相关论文简读

一、YOLOv9简述 自 2015 年 Yolov1 推出以来,已经出现了多个版本。 基于Darknet的YOLOv2、YOLOv3和YOLOv4 YOLOv5 YOLOv8 基于 Ultralytics。 SCALED-YOLOv4 使用 Pytorch 而不是 Darknet。 YOLOR是YOLOv4的改进。 YOLOX是YOLOv3的改进。 YOLOv6专注于工业应用。 YOLOv7 来自 …

哇去,有了这篇文章,项目中引入了再多的字体包,我都不怕了!!!

通常情况下&#xff0c;我们在开发一个新项目的时候&#xff0c;项目那边通常都会提供一些项目所需的字体包&#xff0c;来满足项目对字体展示的特殊需求。 这部分大家都比较熟悉&#xff0c;就不详细讲了&#xff0c;直接上代码&#xff1a; /* 引入字体包 */ font-face {fo…

异常处理(黑马学习笔记)

当前问题 登录功能和登录校验功能我们都实现了&#xff0c;下面我们学习下今天最后一块技术点&#xff1a;异常处理。首先我们先来看一下系统出现异常之后会发生什么现象&#xff0c;再来介绍异常处理的方案。 我们打开浏览器&#xff0c;访问系统中的新增部门操作&#xff0…

模型优化_如何提高网络/模型的泛化能力?(全面)

目录 1. 以数据为中心的泛化方法 1.1 使用更多数据 1.2 做好数据预处理 特征工程 1.3 数据增强 1.4 调整数据分布 2. 以模型为中心的泛化方法 2.1 使用更大批次 超参数调优 2.2 调整目标函数 2.3 调整网络结构 2.4 屏蔽网络节点 2.5 权值正则化 2.6 偏差-方差权衡…

全国夜间灯光指数数据、GDP密度分布、人口密度分布、土地利用数据、降雨量数据

引言 DMSP/OLS的1992-2013年全球遥感影像&#xff0c;包括三种非辐射定标的夜间灯光影像。三种全年平均影像分别是&#xff1a;无云观测频数影像、平均灯光影像和稳定灯光影像。目前地理遥感生态网可提供全国稳定灯光影像免费下载。稳定灯光影像是标定夜间平均灯光强度的年度栅…

【论文阅读笔记】Explicit Visual Prompting for Low-Level Structure Segmentations

1.介绍 Explicit Visual Prompting for Low-Level Structure Segmentations 低级结构分割的显式视觉提示 2023年发表在IEEE CVPR Paper Code 2.摘要 检测图像中低级结构&#xff08;低层特征&#xff09;一般包括分割操纵部分、识别失焦像素、分离阴影区域和检测隐藏对象。虽…

人造太阳光热模拟能量密度太阳模拟器

人造太阳模拟器其他名称&#xff1a;能量密度太阳能光热模拟能量密度太阳模拟器、能流密度太阳光模拟器、高通量太阳模拟器 高通量能留密度太阳能炉和太阳光模拟器产生高度集中的太阳能和人造光&#xff0c;用于新技术和材料的研究和测试。这使研究人员能够进行制氢实验、太阳…

备战蓝桥杯---线段树基础1

引入&#xff1a;RMQ问题&#xff1a; 什么是RMQ&#xff1f; 显然&#xff0c;我们无法用前缀维护&#xff0c;因此&#xff0c;我们需要用到线段树的知识&#xff1a; 什么是线段树&#xff1f; 线段树是用一种树状结构存储一个连续区间信息的数据结构 下面我们用图解释用…

【数据结构】队列OJ题《用队列实现栈》(题库+解析+代码)

1.前言 通过前面队列的实现和详解大家对队列应该有一定熟悉了&#xff0c;现在上强度开始做题吧 队列详解&#xff1a;http://t.csdnimg.cn/dvTsW 2.OJ题目训练225. 用队列实现栈 题目分析 请你仅使用两个队列实现一个后入先出&#xff08;LIFO&#xff09;的栈&#xff0…

【GPU驱动开发】- AST简介

前言 不必害怕未知&#xff0c;无需恐惧犯错&#xff0c;做一个Creator&#xff01; AST&#xff0c;抽象语法树&#xff0c;是一种包含丰富语义信息的格式&#xff0c;其中包括类型、表达式树和符号等。 TranslationUnitDecl&#xff1a;该类表示一个输入源文件 ASTContext&…

Qt注册类对象单例与单类型区别

1.实现类型SingletonTypeExample #ifndef SINGLETONTYPEEXAMPLE_H #define SINGLETONTYPEEXAMPLE_H#include <QObject>class SingletonTypeExample : public QObject {Q_OBJECT public://只能显示构造类对象explicit SingletonTypeExample(QObject *parent nullptr);//…

【学习笔记】深度学习实战 | LeNet

简要声明 学习相关网址 [双语字幕]吴恩达深度学习deeplearning.aiPapers With CodeDatasets 深度学习网络基于PyTorch学习架构&#xff0c;代码测试可跑。本学习笔记单纯是为了能对学到的内容有更深入的理解&#xff0c;如果有错误的地方&#xff0c;恳请包容和指正。 参考文献…

KubeEdge 边缘计算

文章目录 1.KubeEdge2.KubeEdge 特点3.KubeEdge 组成4.KubeEdge 架构 KubeEdge # KubeEdgehttps://iothub.org.cn/docs/kubeedge/ https://iothub.org.cn/docs/kubeedge/kubeedge-summary/1.KubeEdge KubeEdge 是一个开源的系统&#xff0c;可将本机容器化应用编排和管理扩展…

蓝牙耳机和笔记本电脑配对连接上了,播放设备里没有显示蓝牙耳机这个设备,选不了输出设备

环境&#xff1a; WIN10 杂牌蓝牙耳机6s 问题描述&#xff1a; 蓝牙耳机和笔记本电脑配对连接上了&#xff0c;播放设备里没有显示蓝牙耳机这个设备&#xff0c;选不了输出设备 解决方案&#xff1a; 1.打开设备和打印机&#xff0c;找到这个设备 2.选中这个设备&#…