springboot 执行事务回滚

    xiaoxiao2022-07-07  190

    方法上加@Transactional注解 1:: throw new RuntimeException(); 2:TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); 示例: @Transactional public int deleteStudentsById(Integer id) { StudentsResponse studentsResponse = studentsDao.getStudentsById(id); try { sysUserClientService.saveUserOrUpdateStudentCount(studentsResponse.getMobile(), -1, studentsResponse.getCityId()); } catch (Exception e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return studentsDao.deleteStudentsById(id); }
    最新回复(0)