java抛出异常的事务回滚

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> SaveOrUpdateExpert() {

        Map<String,Object> retMap = null;
        String msg = "保存成功";
        try {
          。。。coding。。。
        } catch (Exception e) {
            e.printStackTrace();
            msg = "暂存专家注册信息异常";
            throw e;//必须在抛出异常对象(这里是Exception),否则不会回滚
        }


        retMap.put("code",200);
        retMap.put("msg",msg);

        return retMap;
    }

 

如果方法内有捕捉异常,需要在方法上注解异常对应的类型,否则无法回滚。

posted on 2023-09-27 08:22  五官一体即忢  阅读(152)  评论(0)    收藏  举报

导航