当前位置:网站首页>TransactionTemplate 事务编程式写法
TransactionTemplate 事务编程式写法
2022-07-31 05:15:00 【浮生若梦l】
建议使用声明式事务@Transactional(rollbackFor = Exception.class)粒度不够,拆分方法
import org.springframework.transaction.support.TransactionTemplate;
@Autowired
private TransactionTemplate trans;
/**
* 编程式事务
*/
public void transfer() {
//无返回值
trans.executeWithoutResult((status) ->{
boolean save = this.save(t);
if(!save) {
status.setRollbackOnly();
}
});
//有返回值
trans.execute((status) ->{
boolean save = this.save(t);
if(!save) {
status.setRollbackOnly();
}
return new Object();
});
}边栏推荐
- Tencent Cloud Lightweight Server deletes all firewall rules
- 理解js运算符
- Hyper-V新建虚拟机注意事项
- The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
- 一文速学-玩转MySQL获取时间、格式转换各类操作方法详解
- 安装Multisim出现 No software will be installed or removed解决方法
- 【windows】--- SQL Server 2008 超详细安装教程
- UiBot has an open Microsoft Edge browser and cannot perform the installation
- MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
- 【Elastic-Job】分布式调度任务概览篇
猜你喜欢

Take you to understand the MySQL isolation level, what happens when two transactions operate on the same row of data at the same time?

npm WARN config global `--global`, `--local` are deprecated. Use `--location solution

动态规划(一)| 斐波那契数列和归递

Fragmented NFT (Fractional NFT)

What is an EVM Compatible Chain?
Getting to know regular expressions
![[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]](/img/3d/1b65fb33bfbf22da8243df1ab33ed5.png)
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]

Principle analysis of famous website msdn.itellyou.cn

Linux modify MySQL database password

【windows】--- SQL Server 2008 超详细安装教程
随机推荐
MySQL高级语句(一)
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
Android software security and reverse analysis reading notes
Principle analysis of famous website msdn.itellyou.cn
On the side of Ali, tell me what are the application scenarios of message middleware you know?
How to distinguish big and small endian in C language
Understanding of js arrays
微信小程序启动优化
Understanding SSRF, this article is enough
powershell统计文件夹大小
Digital twins will be an important way to enter the "metaverse"
Hyper-V新建虚拟机注意事项
What is an EVM Compatible Chain?
著名网站msdn.itellyou.cn原理分析
js中流程控制语句
Powershell中UTF-8环境中文乱码解决办法
腾讯云GPU桌面服务器驱动安装
Attribute Changer的几种形态
quick-3.6源码修改纪录