@Transactional 默认是当方法抛出RuntimeException 才会回滚,可以使用标签:rollbackFor,Transactional,Exception,回滚,testDel,new,mybatis,plus From: https://blog.51cto.com/u_15862653/5828352
@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(){
...
}