mybatis 回滚记录

Posted _dreamer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 回滚记录的主要内容,如果未能解决你的问题,请参考以下文章

mybatis使用datasourcetransactionmanager管理事务为啥不回滚

mybatis 手动/自动触发事务回滚

MyBatis:事务回滚

mybatis批量导入 ,出现异常全部不添加(回滚)

Mybatis 事物回滚最简单的操作方式

SSM-MyBatis-09:Mybatis中SqlSession的close为什么能造成事务的回滚