@Transactional捕获异常并拿到返回值
2019-11-07 本文已影响0人
指尖架构141319
@Transactional
@Override
public boolean add(Product product) {
try{
Product dept = new Product() ;
dept.setProductName("12");
productMapper.create(dept);
int a = 4/0;
return true;
}catch(Exception e){
//捕获异常并执行回滚,且能拿到返回值false
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
e.printStackTrace();
return false;
}
}