Пример #1
0
  private void menuCheck(Menu menu) throws BusinessException {
    Map<String, String> errors = new HashMap<String, String>(2);

    if (menu.getName() == null || "".equals(menu.getName().trim())) {
      errors.put("name", "菜单名称不能为空!");
    } else if (menu.getName().trim().length() > 20) {
      errors.put("name", "菜单名称不能大于20个字符!");
    }

    if (menu.getTip() != null && menu.getTip().trim().length() > 64) {
      errors.put("tip", "菜单描述不能大于64个字符!");
    }

    if (menu.getAction() != null && menu.getAction().trim().length() > 256) {
      errors.put("action", "菜单动作不能大于256个字符!");
    }

    if (menu.getSorting() == null) {
      // errors.put("sorting", "菜单排序不能为空!");
      // 默认排序为1
      menu.setSorting(1);
    }

    if (menu.getSystemId() == null) {
      errors.put("systemid", "菜单的系统ID不能为空!");
    }

    if (menu.getImg() != null && menu.getImg().trim().length() > 256) {
      errors.put("img", "菜单图片不能大于256个字符!");
    }

    if (!errors.isEmpty()) {
      throw new BusinessException(errors);
    }
  }