spring 事务实验

网友投稿 538 2022-09-09

spring 事务实验

spring 事务实验

转钱

用户A 转账一笔钱给B

不加事务不出现异常

用户A 钱正常减少 用户B 钱正常增加

不加事务出现异常

用户A 钱减少 用户B 钱没有增加

出现异常添加事务

用户A 钱没有减少 用户B 钱没有增加

@Override @Transactional(rollbackFor = Exception.class) 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); }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:wsl设置root密码
下一篇:利用Python写一个抽奖程序,解密游戏内抽奖的秘密
相关文章

 发表评论

暂时没有评论,来抢沙发吧~