1、在数据库中建表
CREATE TABLE `undo_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`branch_id` bigint(20) NOT NULL,
`xid` varchar(100) NOT NULL,
`context` varchar(128) NOT NULL,
`rollback_info` longblob NOT NULL,
`log_status` int(11) NOT NULL,
`log_created` datetime NOT NULL,
`log_modified` datetime NOT NULL,
`ext` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
2、添加依赖
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>2021.1</version>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
3、修改配置文件
seata:
enabled: true
application-id: server-shop-order
registry:
type: file
config:
type: file
service:
grouplist:
default: 127.0.0.1:8091
vgroup-mapping:
server-seata-money: default
tx-service-group: server-seata-money
client:
undo:
log-table: undo_log
4、添加注解
@PostMapping(value = "/swap")
@GlobalTransactional
public ResultVo swap() {
iSwapBeijingService.swapMoney(1, -100);
iSwapShanghaiService.swapMoney(1, 100);
return ResultVo.SUCCESS();
}
@PostMapping(value = "/swapMoney")
@GlobalTransactional
public ResultVo swapMoney(@RequestParam("userId") Integer userId, @RequestParam("money") Integer money) {
return tbMoneyBjService.swapMoney(userId, money);
}
@PostMapping(value = "/swapMoney")
@GlobalTransactional
public ResultVo swapMoney(@RequestParam("userId") Integer userId, @RequestParam("money") Integer money) {
return tbMoneyShService.swapMoney(userId, money);
}
这个工具类在一下目录:
专高5考试附件 6.7\专高5考试附件\专高5月考最新附件1.0\专高5 附件2\微服务\utils\OSSFileUtil.java
String endpoint = "http://oss-cn-beijing.aliyuncs.com";
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
String accessKeyId = "LTAI4FtqoX9aXnwt5WRPVtJ9";
String accessKeySecret = "BjxfqbWKvpusWM328UGzwYT8PQYlm5";
String bucket = "shenmazong";
String ossUrl = "https://images.shenmazong.com/";
@PostMapping(value = "/uploadFile")
public ResultVo uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
String url = ossFileUtil.uploadFile(file);
return ResultVo.SUCCESS(url);
}
@PostMapping(value = "/upload")
public ResultVo upload(@RequestParam("file") MultipartFile file) throws IOException {
String url = ossFileUtil.uploadFileByBreakingPoint(file);
return ResultVo.SUCCESS(url);
}
在controller里面,需要注入上传的工具类
@Autowired
OSSFileUtil ossFileUtil;