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,结果同样为空.如下图.
实体类不要用基本类型,可以先试试 Boolean,如果有问题,把SQL贴出来看看。