栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

spring 事务实验

spring 事务实验

存钱 不加事务不出现异常

正常修改

不加事务出现异常

只减少了钱 没有增加钱

出现异常添加事务

事务出现回滚 数据一致性有保障

也可以加到 ServiceImpl 上

 @Override
 public void transferMoney(Long send, Long receive, BigDecimal money) {
     UserAccount one = this.lambdaQuery().eq(UserAccount::getId, send).one();
     UpdateWrapper sendWrapper = new UpdateWrapper<>();
     sendWrapper.eq("id",send).set("money",one.getMoney().subtract(money));
     this.update(sendWrapper);
     int i = 0;
     final int res = 10 / i;
     UserAccount two = this.lambdaQuery().eq(UserAccount::getId, receive).one();
     UpdateWrapper receiveWrapper = new UpdateWrapper<>();
     receiveWrapper.eq("id",receive).set("money",two.getMoney().add(money));
     this.update(receiveWrapper);
 }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/748462.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号