编程试事物

来源:互联网 发布:计算机科学和编程导论 编辑:程序博客网 时间:2024/05/29 12:23

 transactionTemplate.execute


 @Override

//在编程事物中

    public boolean saveUser(final UserModel um,final String person) {
     boolean execute = (boolean) this.transactionTemplate.execute(new TransactionCallback<Object>() {
     @Override
     public Object doInTransaction(TransactionStatus status) {
     boolean fag = false;
             try {
     //业务处理成功
             fag=true;
     } catch (Exception e) {

     log.error("Exception ={}",e);

//在异常的情况下回滚

     status.setRollbackOnly();
     throw new Exception();
     }
return fag;
     }});
        return execute;
    }

 

0 0