spring手动让事务回滚

spring手动让事务回滚

可以使用**TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();**进行手动回滚

@Transactional
    public void methodC() {

        UserDo userDo = new UserDo();
        userDo.setMobile("999");
        userDo.setUserName("imya");
        userDao.insert(userDo);
        try {
            this.methodA();
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        this.methodB();
    }

你可能感兴趣的:(spring)