Java事务回滚需要添加
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
serviceImplement完整代码如下:
//删除用户
@Transactional(rollbackFor=Exception.class)
public boolean deleteUser(String userIds) {
int failflag = 0;
if(!Constant.isEmpty(userIds)) {
String[] userId = userIds.split(",");
if(userId.length!=0) {
for(int i=0;i<userId.length;i++) {
if(!userDao.deleteUser(Integer.valueOf(userId[i]))) {
failflag = failflag +1;
}
}
}
}
if(failflag==0) {
return true;
}else {
//数据回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return false;
}
}