无论我做什么,结果总是错误的。
我的列表定义如下:
private List<String> selectedPriorities;
在 getter/setter 上没有任何奇怪或花哨的东西:
public void setSelectedPriorities(List<String> selectedPriorities) {
this.selectedPriorities = selectedPriorities;
}
public List<String> getSelectedPriorities() {
return selectedPriorities;
}
在一个会话bean中,我想基于这个列表的内容(或者缺少内容)来修改不同的列表。
以下是代码:
List<String> restrictList = new ArrayList<String>();
restrictList.add("lower(logs.clazz) like lower(concat(#{logs.clazz},'%'))");
restrictList.add("lower(logs.rule) like lower(concat(#{logs.rule},'%'))");
PrioritySelectorBean selectorBean = (PrioritySelectorBean) Component.getInstance("prioritySelectorBean",true);
System.out.println("constructRestrictionList selectorBean "+selectorBean.getSelectedPriorities());
if (selectorBean.getSelectedPriorities() == null) {
System.out.println("IS NULL");
return restrictList;
}
if (selectorBean.getSelectedPriorities().isEmpty()){
System.out.println("IS EMPTY");
}
if (selectorBean.getSelectedPriorities().size()<1){
System.out.println("HAS NOTHING IN IT");
return restrictList;
}
System.out.println("NOT NULL");
restrictList.add("lower(logs.priority) in (#{prioritySelectorBean.selectedPriorities})");
它总是落到NOT NULL上,并将字符串添加到restrictList中。这让我疯了!我该如何检测这个列表中的空值?以下是日志片段:
14:24:10,057 INFO [STDOUT] constructRestrictionList selectorBean []
14:24:10,057 INFO [STDOUT] NOT NULL