数据库回滚-@Transactional

使用@Transactional,当方法内出现异常时进行数据库回滚

  @Transactional(rollbackFor = Exception.class)
    @Override
    public BaseResponse approvalPerson(Person person) throws Exception{
        BaseResponse response = new BaseResponse();
        try {
            Boolean ret = personMapper.approvalPerson(person);
            if (ret && person.getStatus() == 2){
                。。。
            }
        } catch (Exception e) {
            logger.error("approvalPerson error: ",e);
            response.setCode(DefaultErrorCode.ERROR.getCode());
            response.setMsg("审批失败");
            response.setData(e.getMessage());
            throw new Exception("test4 error");
        }
        return response;
    }

 

上一篇:Spring 如何在一个事务中开启另一个事务?


下一篇:spring中手动回滚