在方法上添加事务,并且在方法内有try catch块,
@Override @Transactional(value = "mysqlTransactionManager",rollbackFor = BusinessException.class) public void saveVisitRecord(PeopleVisitRecord peopleVisitRecord) { try { peopleVisitRecordMapper.insertSelective(peopleVisitRecord); } catch (Exception e) { LOGGER.error("更新访谈记录失败,[]", e); throw new BusinessException("新增访谈记录失败"); } }
在没有添加value = "mysqlTransactionManager"时会报如下异常:
Could not commit JDBC transaction; nested exception is java.sql.SQLException: You have an error in your SQL syntax near 'commit'",
添加后正常