当前位置:网站首页>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();
});
}边栏推荐
- quick-3.5 无法使用模拟器修改
- Build DVWA with phpstudy
- [windows]--- SQL Server 2008 super detailed installation tutorial
- 【Elastic-Job源码分析】——作业监听器
- For penetration testing methods where the output point is a timestamp (take Oracle database as an example)
- 【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
- Pure shell implementation of text replacement
- cocos2d-x-3.2创建项目方法
- Markdown 帮助文档
- 常见JVM面试题及答案整理
猜你喜欢

【Elastic-Job源码分析】——作业监听器

MySQL高级语句(一)

Sqlite A列数据复制到B列

【云原生】微服务Nacos的简单介绍与使用

Linux修改MySQL数据库密码

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

场效应管 | N-mos内部结构详解

Android software security and reverse analysis reading notes

【swagger关闭】生产环境关闭swagger方法
![[Elastic-Job source code analysis] - job listener](/img/99/5e047b1aa83aad7d7f17b4eec606e6.png)
[Elastic-Job source code analysis] - job listener
随机推荐
Install mysqldb in mac10.14
MySQL压缩包方式安装,傻瓜式教学
The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
Digital twins will be an important way to enter the "metaverse"
Android software security and reverse analysis reading notes
SQLite 查询表中每天插入的数量
SSH自动重连脚本
计网 Packet Tracer仿真 | 简单易懂集线器和交换机对比(理论+仿真)
sql 外键约束【表关系绑定】
sqlite 查看表结构 android.database.sqlite.SQLiteException: table splitTable has no column named
What is an EVM Compatible Chain?
unicloud 云开发记录
configure:error no SDL library found
On the side of Ali, tell me what are the application scenarios of message middleware you know?
纯shell实现文本替换
"limit" query in Oracle database
理解js运算符
quick-3.6源码修改纪录
cocoscreator3.5.2打包微信小游戏发布到QQ小游戏修改
GUCCI, LV and other luxury giant universe how to layout yuan, other brands should keep up with?