List helpQuestion =
null;
//定义一个list对象 初始化为null
helpQuestion=this.helpQuestionServ.getHelpQuestion(helpCenter.getId());
//helpCenter表的id即helpQuestion表的helpID 一对多关系
根据helpID查询出几条数据放到helpQuestion里
if(helpQuestion.size()>0){//list对象非空判断
this.addError("该帮助关联问题非空,不能删除!");
//弹出错误提示框
}else if(helpQuestion == null ||
helpQuestion.size()==0){//第一个条件判断list是否存在
第二个条件判断list里是否有值
this.helpCenterServ.remove(helpCenter.getId());
//根据id删除该条数据
this.addMessgae("操作成功!");
}
1.开始用的if(helpQuestion !=
null){。。}else{。。} ,结果断点helpQuestion值:[null, null, null, null, null,
null, null, null, null, null] 然后竟然走if{};不是都空吗,该走else啊,list里的键不空
对应的值为空, list对象不能用null判断
2.helpQuestion.size()>0代表helpQuestion里至少有一条数据
即非空判断 搞定
3.还可以 if(helpQuestion != null
&&
!helpQuestion.isEmpty())条件1代表该对象存在,不成立的话不判断条件2,成立再判断条件2helpQuestion里是否有值即非空判断