天天看点

Transactional mybatis plus 不生效

@Transactional 默认是当方法抛出RuntimeException 才会回滚,可以使用
 
@Transactional(rollbackFor = Exception.class) 指定具体异常时 就回滚
 
代码:
 
@Transactional(rollbackFor = Exception.class)
public void testDel() throws Exception {
        Map<String,Object> params = new HashMap<>();      
        if(true){
                throw new Exception("测试");
        }
}
 
然后在controller 或service 调用该方法时时 去获取异常
try{
testDel()
}catch(){
...
}      

继续阅读