当前位置:网站首页>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();
});
}
边栏推荐
- Xiaobai learns reptiles - introduction to reptiles
- 数字孪生将成为进入“元宇宙”一项重要的途径
- Chinese garbled solution in UTF-8 environment in Powershell
- npm WARN config global `--global`, `--local` are deprecated. Use `--location解决方案
- this指向问题
- [Cloud native] Simple introduction and use of microservice Nacos
- mysql常用命令
- 【云原生】微服务Nacos的简单介绍与使用
- 2021 Mianjing - Embrace Change
- unicloud 云开发记录
猜你喜欢
mysql password modification method in Linux (pro-test available)
小米手机短信定位服务激活失败
Fragmented NFT (Fractional NFT)
Android software security and reverse analysis reading notes
Artifact SSMwar exploded Error deploying artifact.See server log for details
this指向问题
Build DVWA with phpstudy
MySQL-如何分库分表?一看就懂
数字孪生将成为进入“元宇宙”一项重要的途径
DeFi Token in the project management
随机推荐
网页截图与反向代理
Fragmented NFT (Fractional NFT)
微信小程序源码获取与反编译方式
js中的break与continue退出
通信原理——纠错编码 | 汉明码(海明码)手算详解
Judgment of database in SQL injection
使用ps | egrep时过滤排除掉egrep自身
Principle analysis of famous website msdn.itellyou.cn
Year-end summary - the years are quiet~
[swagger close] The production environment closes the swagger method
SQLite 查询表中每天插入的数量
this points to the problem
【Elastic-Job源码分析】——作业监听器
mysql password modification method in Linux (pro-test available)
Access database query
Why does read in bash need to cooperate with while to read the contents of /dev/stdin
带你搞懂MySQL隔离级别,两个事务同时操作同一行数据会怎样?
Linux中mysql密码修改方法(亲测可用)
浅谈对分布式模式下CAP的理解
cocos2d-x 实现跨平台的目录遍历