springboot 执行事务回滚

方法上加@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);
	}

你可能感兴趣的:(springboot 执行事务回滚)