mybatis 回滾記錄
阿新 • • 發佈:2017-08-14
exception sql this run use mybatis number except 進行
@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 回滾記錄