@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; }
如果方法内有捕捉异常,需要在方法上注解异常对应的类型,否则无法回滚。