参考:https://www.cnblogs.com/0201zcr/p/5962578.html
@Transactional(rollbackOn = { Exception.class })
public void test() {
try {
doDbStuff1();
doDbStuff2();
} catch (Exception e) {
e.printStackTrace();
//就是这一句了,加上之后,如果doDbStuff2()抛了异常,doDbStuff1()是会回滚的
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
}
网友评论