标签:getmenu 图片 透明 机构 code mamicode first 模拟 二级菜单
package composite; import java.util.List; public class Menu { private String menuName; private List<Menu> childMenus; public Menu(String menuName,List<Menu> childMenus){ this.menuName = menuName; this.childMenus = childMenus; } public String getMenuName() { return menuName; } public List<Menu> getChildMenus() { return childMenus; } @Override public String toString() { return "["+menuName+"]"; } } package composite; import java.util.ArrayList; import java.util.List; public class Client { public static void main(String[] args){ //初始化模拟数据 List<Menu> firstSubList = new ArrayList<>(); List<Menu> secondSubList =new ArrayList<>(); firstSubList.add(new Menu("二级菜单-无子菜单",null)); firstSubList.add(new Menu("二级菜单-有子菜单",secondSubList)); secondSubList.add(new Menu("三级子菜单1",null)); secondSubList.add(new Menu("三级子菜单2",null)); Menu menu = new Menu("主菜单",firstSubList); //客户打印菜单树 printMenu(menu); } //递归打印菜单树 public static void printMenu(Menu menu){ System.out.println(menu); if(menu.getChildMenus()!=null&&menu.getChildMenus().size()>0){ for(Menu subMenu:menu.getChildMenus()){ printMenu(subMenu); } } } }
标签:getmenu 图片 透明 机构 code mamicode first 模拟 二级菜单
原文地址:https://www.cnblogs.com/camcay/p/12368248.html