示例#1
0
 @NeedCache
 public MenuBean findMenuByCode(String code) {
   for (MenuBean menu : menuList) {
     /*忽略大小写判断是否相等*/
     if (!StringUtils.endsWithIgnoreCase(menu.getCode(), code)) continue;
     return menu;
   }
   return null;
 }
示例#2
0
 /*从构造方法中注入 AppContext 接口对象*/
 @Inject
 public MenuServices(AppContext appContext) {
   this.menuList = new ArrayList<MenuBean>();
   /*获取操纵配置文件的接口*/
   Settings setting = appContext.getSettings();
   /*取得‘/demoProject/menus’ Xml节点*/
   XmlNode xmlNode = setting.getXmlNode("demoProject.menus");
   /*使用 DOM 方式解析 Xml节点*/
   List<XmlNode> menus = xmlNode.getChildren("menu");
   for (XmlNode node : menus) {
     MenuBean menuBean = new MenuBean();
     menuBean.setCode(node.getAttribute("code"));
     menuBean.setName(node.getAttribute("name"));
     menuBean.setUrl(node.getAttribute("url"));
     menuList.add(menuBean);
   }
 };