spring boot 会自动配置一个 DataSourceTransactionManager,我们只需在方法(或者类)加上 @Transactional 注解,就自动纳入 Spring 的事务管理。
@Transactional
public void save() {
Student student = new Student("小明");
int c = studentMapper.insert(student);
if (c < 1) {
throw new RuntimeException("异常");
}
}