Spring boot @Transactional

 

1.注解@Transactional

2.异常回滚 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();

@Override
@UDS(value="fq")
@Transactional
public BaseResultMessage testTransactional(){
BaseResultMessage rm = Utils.baseDefaultResultMessageSuccess();
TestEntity test = new TestEntity();
test.setId(5);
test.setName("xx");
int i = otherOrderInMapper.insetTest(test);

try{
int m=10/0;
}catch (Exception e) {
logger.error("==> 异常回滚!");
rm.setType(false);
rm.setMsg(" 异常回滚");
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}

return rm;
}

posted @ 2019-08-12 16:58  A汉克先生  阅读(208)  评论(0编辑  收藏  举报