1.生成實體類
2.生成JSON數據格式的方法
//存返回數據
List<Menus> totaltype = new ArrayList<>();
//使用map來裝前面查到的所有數據
Map<Integer, Menus> map = new HashMap<>();
for (Menus p:allMenus){
map.put(p.getId(),p);
}
//遍歷所有類型,如果是最頂級父類型就直接裝, 然后用這個父類型的children集合取裝取當前數據
for(Menus p:allMenus){
if(p.getParentid()==0){
totaltype.add(p);
}else{
Menus parents=map.get(p.getParentid());
parents.getChirdenList().add(p);
}
}
return totaltype;
`