@Transactional(rollbackFor = Exception.class, readOnly = false)

@Transactional 是声明式事务管理 编程中使用的注解

@Transactional(rollbackFor = Exception.class, readOnly = false) 即将捕捉到的Exception异常全部回滚

如下测试:

TestServiceImpl

未加注解@Transactional(rollbackFor = Exception.class, readOnly = false):

测试结果:满足条件的存入表内,未满足条件的不存


添加注解@Transactional(rollbackFor = Exception.class, readOnly = false):

测试如下:无论是否满足条件,因为注解对事务的作用,全部未加入表中

你可能感兴趣的:(@Transactional(rollbackFor = Exception.class, readOnly = false))