Mybatis 事物回滚

添加注解 @Transactional

如果flag经过一系列操作为false,事务回滚

    @Transactional
    @RequestMapping(value = "/test")
    public Result test(@RequestBody Abc aaa) {
        Abc abc = sysService.getById(aaa.getId());
        if (null == abc || null == abc) {
            return ResultUtil.sendErrorMessage("失败!");
        }
        sysService.save(aaa);
        boolean flag = false;
        ……
        ……
        if (flag) {
            return ResultUtil.sendSuccessMessage("成功!");
        } else {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultUtil.sendErrorMessage("失败!");
        }
    }

 

posted @ 2020-05-08 11:42  慕尘  阅读(419)  评论(0编辑  收藏  举报