首页 > 代码库 > mybatis 回滚记录
mybatis 回滚记录
@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;
}
mybatis 回滚记录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。