使用@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; }