public JSONArray getTreeNodes(String departmentSn) {
Department department = new Department();
JSONArray jsonArray = new JSONArray();
if (!departmentSn.equals("-1")) {
department.setParentDepartmentSn(departmentSn);
} else {
//这里将department的一个布尔属性设置为true
department.setHasActivated(true);
}
//在这里进行筛选
List<Department> departments = departmentMapper.select(department);
System.out.print(departments);
for (Department DEP : departments) {
Department d = new Department();
Department sonDepartment = departmentMapper.selectByPrimaryKey(DEP.getDepartmentSn());
JSONObject jsonObject = new JSONObject();
jsonObject.put("label", sonDepartment.getDepartmentName());
jsonObject.put("data", sonDepartment.getDepartmentSn());
d.setParentDepartmentSn(DEP.getDepartmentSn());
if (departmentMapper.selectCount(department) == 0) {
jsonObject.put("leaf", true);
} else {
jsonObject.put("leaf", false);
}
jsonArray.add(jsonObject);
}
return jsonArray;
}
}
在上面的程式碼中,當我傳入一個不為-1的departmentSn進來時,它並沒有進入else分支,然而經過下面的篩選後結果集為空,如下圖
此處size為0.
而當我將實體類別中的boolean屬性改為string屬性後(如圖)
修改前
修改後
篩選結果就正常了.
此處size為8.
這是為什麼呢?
另外,我還嘗試了手動將boolean屬性賦為false,結果同樣為空.如下圖.
#