Controller
我这里传递的是字符串 循环取值
@ResponseBody
@RequestMapping(value = "/DimensionsSelect")
public Map<String, Object> SelectFindFileName(String selectVos) {
Map<String, Object> map = new HashMap<>(16);
List<String> labels = new ArrayList<>(); //返回所有的树结构的label
Gson gson = new Gson();
DimensionsSelectVo dimensionsSelectVo = gson.fromJson(selectVos, DimensionsSelectVo.class);
List<DimensionsSelectVo> children = dimensionsSelectVo.getChildren();
if (dimensionsSelectVo.getChildren() == null) {
labels.add(dimensionsSelectVo.getTitle());
List<PartDataEntity> partDataEntities = service.FindIdList(labels);
map.put("data", partDataEntities);
return map;
} else {
for (DimensionsSelectVo tree : children) {
labels.addAll(DimensionsSelectUtil.selectChildren(tree)); //查询树结构的子节点
}
System.out.println("------------------------>>>>>>>>>>>>>>>" + labels.size());
List<PartDataEntity> partDataEntities = service.FindIdList(labels);
map.put("data", partDataEntities);
return map;
}
}
utils
循环取值getTitle,感谢曾经帮助的人
/**
* 递归查询某一个值
*
* @param tree
* @return
*/
public static List<String> selectChildren(DimensionsSelectVo tree) {
List<String> labels = new ArrayList<>();
labels.add(tree.getTitle());
if (tree.getChildren() != null) {
for (DimensionsSelectVo children : tree.getChildren()) {
List<String> children_label = selectChildren(children); //递归查询
labels.addAll(children_label);
}
}
return labels;
}