当前位置:网站首页>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();
});
}边栏推荐
- 【uiautomation】微信好友列表获取(存储到txt中)
- cocoscreator 显示刘海内容
- MySQL compressed package installation, fool teaching
- flutter 混合开发 module 依赖
- Regular Expression Basics
- MySQL高级SQL语句(二)
- Pure shell implementation of text replacement
- Chinese garbled solution in UTF-8 environment in Powershell
- [windows]--- SQL Server 2008 super detailed installation tutorial
- 对js的数组的理解
猜你喜欢
![[Elastic-Job source code analysis] - job listener](/img/99/5e047b1aa83aad7d7f17b4eec606e6.png)
[Elastic-Job source code analysis] - job listener

常见JVM面试题及答案整理

Linux中mysql密码修改方法(亲测可用)

场效应管 | N-mos内部结构详解
![[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]](/img/3d/1b65fb33bfbf22da8243df1ab33ed5.png)
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]

数据库 | SQL增删改查基础语法
![[JVM Loading]---Class Loading Mechanism](/img/b6/d1754cb6699d18602ca9a463571c0c.png)
[JVM Loading]---Class Loading Mechanism

Chinese garbled solution in UTF-8 environment in Powershell

为什么bash中的read要配合while才能读取/dev/stdin的内容

一文速学-玩转MySQL获取时间、格式转换各类操作方法详解
随机推荐
小白学爬虫——爬虫入门
一文速学-玩转MySQL获取时间、格式转换各类操作方法详解
数据库 | SQL查询进阶语法
MySQL-如何分库分表?一看就懂
[Cloud native] Open source data analysis SPL easily copes with T+0
quick-3.6源码修改纪录
MySQL compressed package installation, fool teaching
cocoscreator3.5.2打包微信小游戏发布到QQ小游戏修改
Artifact SSMwar exploded Error deploying artifact.See server log for details
2021 Mianjing - Embrace Change
NFTs: The Heart of Digital Ownership
The server time zone value ‘й‘ is unrecognized or represents more than one time zone
著名网站msdn.itellyou.cn原理分析
cocos2d-x-3.2创建项目方法
SQLite 查询表中每天插入的数量
MySQL高级SQL语句(二)
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
[Cloud Native] What should I do if SQL (and stored procedures) run too slowly?
最新MySql安装教学,非常详细
C language tutorial (3) - if and loop