方法上加@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 执行事务回滚
最新推荐文章于 2024-08-02 16:10:35 发布