SpringBoot事务支持:

1.在入口类中使用@EnableTransactionManagement开启事务支持;

springboot学习总结六(Spring boot下事务配置管理)

2.在访问数据库的Service方法上添加注解@Transactional即可

StudentService.java

springboot学习总结六(Spring boot下事务配置管理)

StudentServiceImpl.java

springboot学习总结六(Spring boot下事务配置管理)

MyBaitsController.java

springboot学习总结六(Spring boot下事务配置管理)

执行结果分析:

除数不能为零,会抛出运行时异常,上一步的结果就会回滚

springboot学习总结六(Spring boot下事务配置管理)

数据库查询数据结果未改变:

springboot学习总结六(Spring boot下事务配置管理)

把@Transactional注解去掉,数据库数据结果进行更新:

springboot学习总结六(Spring boot下事务配置管理)

 

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-06-25
  • 2021-09-09
  • 2021-08-30
  • 2021-10-19
  • 2021-07-11
  • 2021-05-21
猜你喜欢
  • 2022-01-01
  • 2021-09-14
  • 2021-04-13
  • 2022-12-23
  • 2021-07-21
  • 2021-05-17
相关资源
相似解决方案