我有以下数据库
我使用Map For General information group father
public static Map<String, List<TblCategory>> mapHierarchy() {
Map<String, List<TblCategory>> mapHierarchy = new HashMap<>();
try {
prepareStatement = connection.prepareStatement("SELECT * FROM `TblCategory` ORDER BY `name`");
resultSet = prepareStatement.executeQuery();
while (resultSet.next()) {
TblCategory TblCategory = new TblCategory();
TblCategory.setID(resultSet.getString("parentID"));
List<TblCategory> memberHierarchy = mapHierarchy.get(TblCategory.getParentID());
if (memberHierarchy == null) {
memberHierarchy = new ArrayList<>();
mapHierarchy.put(TblCategory.getParentID(), memberHierarchy);
}
TblCategory.setName(resultSet.getString("name"));
memberHierarchy.add(TblCategory);
}
} catch (SQLException ex) {
Logger.getLogger(HierarchyServices.class.getName()).log(Level.SEVERE, null, ex);
}
return mapHierarchy;
}
我使用地图创建一个多层菜单,我不知道如何在这里执行我继续做的事
CheckBoxTreeItem cbtHierarchy;
CheckBoxTreeItem<String> cbtNameParent;
CheckBoxTreeItem<String> cbtName;
public void initialize(URL url, ResourceBundle rb) {
Map<String, List<TblCategory>> mapHierarchy = HierarchyServices.mapHierarchy();
mapHierarchy.forEach((String t, List<TblCategory> u) -> {
showHierarchy(t, u, cbtHierarchy);
});
}
private void showHierarchy(String primary, List<TblCategory> u, CheckBoxTreeItem<String> cbtHierarchy) {
if (primary.isEmpty()) {
cbtParentName = new CheckBoxTreeItem<>(primary);
cbtHierarchy.getChildren().add(cbtParentName);
} else {
showHierarchy(TblCategory.getParentID(), HierarchyServices.mapHierarchy().get(TblCategory.getParentID()), cbtHierarchy);
}
}
请帮帮我