Exemple #1
0
  /**
   * 添加/修改菜单 修改选中的菜单,为该菜单添加子菜单
   *
   * @return
   * @throws Exception
   */
  @RequestMapping(value = "addOrUpdate", method = RequestMethod.POST)
  @ResponseBody
  public String addOrUpdate(HttpServletRequest request) throws Exception {
    // 选中菜单的信息
    String updateP = request.getParameter("updateP");
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String orderNum = request.getParameter("orderNum");
    String type = request.getParameter("type");

    // 要添加的子菜单
    String url = request.getParameter("url");
    String n_name = request.getParameter("n_name");
    String n_url = request.getParameter("n_url");
    String parentOrChild = request.getParameter("parentOrChild");
    String n_orderNum = request.getParameter("n_orderNum");
    String n_type = request.getParameter("n_type");

    Menu itemMenu = null;
    if (n_name != null && !n_name.trim().equals("")) {
      itemMenu = new Menu();
      // 添加子菜单
      if (parentOrChild.equals("0")) { // 顶级模块
        itemMenu.setPid("0");
        itemMenu.setType(MenuType.module.toString());
      } else if (parentOrChild.equals("1")) { // 顶级页面
        itemMenu.setPid("0");
        itemMenu.setType(MenuType.page.toString());
      } else if (parentOrChild.equals("2")) { // 子模块
        itemMenu.setPid(id);
        itemMenu.setType(MenuType.module.toString());
      } else if (parentOrChild.equals("3")) { // 子页面
        itemMenu.setPid(id);
        itemMenu.setType(MenuType.page.toString());
      } else if (parentOrChild.equals("4")) { // 功能
        itemMenu.setPid(id);
        itemMenu.setType(MenuType.button.toString());
      } else {
        throw new IllegalAccessException("添加菜单异常。");
      }
      itemMenu.setName(n_name);
      itemMenu.setUrl(n_url);
      itemMenu.setOrderNum(Integer.valueOf(n_orderNum));
      itemMenu.setType(n_type);
    }
    // 修改父菜单
    Menu m = new Menu();
    m.setId(id);
    m.setName(name);
    m.setUrl(url);
    m.setOrderNum(Integer.valueOf(orderNum));
    m.setType(type);

    menuService.addOrUpdate(updateP, m, itemMenu);

    return "ok";
  }
Exemple #2
0
 @RequestMapping(value = "save", method = RequestMethod.POST)
 public String save(@ModelAttribute("e") Menu menu) throws Exception {
   if (menu.getId() == null || menu.getId().equals("")) {
     if (menu.getUrl() == null) {
       menu.setUrl("");
     }
     menuService.insert(menu);
   } else {
     menuService.update(menu);
   }
   return selectList(RequestHolder.getRequest(), menu);
 }