@Transactional public int addThumbsUp(Map map) throws Exception{ int result = 0;//如果调用其他方法执行sql,不进行回滚// int addGroupPoint = this.addGradeGroupPoint(map);// int addOrderedNumberByUserId = this.addOrderedNumberByUserId(map);// int addPointNumberByUserId = this.addPointNumberByUserId(map);// int createThumbsUp = this.createThumbsUp(map); //在当前方法内执行sql,抛出RuntimeException 异常 回滚。 int addGroupPoint = this.template.update("ThumbsUp.addGradeGroupPoint",map); int addOrderedNumberByUserId = this.template.update("ThumbsUp.addOrderedNumberByUserId",map); int addPointNumberByUserId = this.template.update("ThumbsUp.addPointNumberByUserId",map); int createThumbsUp = this.template.insert("ThumbsUp.createThumbsUp",map); //如果记录为零,则认为失败 if(addOrderedNumberByUserId == 0){ throw new RuntimeException("失败"); } if(addPointNumberByUserId == 0){ throw new RuntimeException("失败"); } if(createThumbsUp == 0){ throw new RuntimeException("失败"); } if(addGroupPoint == 0){ throw new RuntimeException("失败"); } // result = ((addGroupPoint == 0 ? (addOrderedNumberByUserId == 0 ? 0 : ) : 0) == 0 ? 0 : addPointNumberByUserId) == 0 ? 0 : createThumbsUp;// result = addGroupPoint == 0 ? 0 : (addOrderedNumberByUserId == 0 ? 0 : (addPointNumberByUserId == 0 ? 0 : (createThumbsUp == 0 ? 0 : createThumbsUp))) if(addGroupPoint == 0 || addOrderedNumberByUserId == 0 || addPointNumberByUserId == 0 || createThumbsUp == 0){ result = 0; }else{ result = 1; } return result; }
时间: 2024-11-10 11:40:00