@Transactional
1.在接口Service增加 @Transactional注解
2.该接口是public 而且抛出了异常
public void testTransction(Vo vo) throws Exception;
3.在接口实现类抛出 RuntimeException 异常
@Override public void testTransction(Bo bo) throws Exception {
//修改开始和下一步的信息 dao.updateByPrimaryKeySelective(bo); throw new RuntimeException("运行期例外"); }
声明式事务
@Override public void editTask(DbTaskConfigSumVo dbTaskConfigSumVo) throws Exception { TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); try{ //具体代码逻辑 transactionManager.commit(status); } catch (Exception e){ // 捕获异常时 事务回滚(避免先删除了数据在后续的操作中报错使得新增失败,而数据又被删了) transactionManager.rollback(status); LOG.error(e); throw e; }