Beispiel #1
0
 /** @author 添加新的目录 */
 @ResponseBody
 @RequestMapping(value = "/add.json", method = RequestMethod.POST)
 public JsonVo<String> add(
     @RequestParam(value = "fatherId", defaultValue = "0") long fatherId,
     @RequestParam(value = "folderName") String folderName,
     @RequestParam(value = "folderEname") String folderEname,
     @RequestParam(value = "status") FolderConstant.Status status,
     ModelMap modelMap) {
   JsonVo<String> json = new JsonVo<String>();
   // FIXME 检查目录的ename不能用循环遍历检查
   List<FolderVo> list = folderService.getAllFolderList(0, null);
   try {
     if (StringUtils.isBlank(folderName)) {
       json.getErrors().put("folderName", "目录名称不能为空");
     }
     if (StringUtils.isBlank(folderEname)) {
       json.getErrors().put("folderEname", "英文名称不能为空");
     } else if (!RegexUtils.isAlphaUnderline(folderEname)) {
       json.getErrors().put("folderEname", "只能是英文字母,数字和下划线");
     } else {
       for (Folder folder : list) {
         if (folderEname.equals(folder.getEname())) {
           json.getErrors().put("folderEname", "英文名称不能重复");
         }
       }
     }
     // 检测校验结果
     validate(json);
     folderService.addFolder(
         fatherId,
         folderName,
         status,
         folderEname.toLowerCase(),
         FolderConstant.Rank.everyone,
         FolderConstant.Type.folder);
     json.setResult(true);
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
     json.setResult(false);
     json.setMsg(e.getMessage());
   }
   return json;
 }
Beispiel #2
0
  /** @author 修改目录资料 */
  @ResponseBody
  @RequestMapping(value = "/update.json", method = RequestMethod.POST)
  public JsonVo<String> updateFolder(
      @RequestParam(value = "folderId") long folderId,
      @RequestParam(value = "name") String name,
      @RequestParam(value = "ename") String ename,
      @RequestParam(value = "content", required = false) String content) {

    JsonVo<String> json = new JsonVo<String>();
    // FIXME 检查目录的ename不能用循环遍历检查
    List<FolderVo> list = folderService.getAllFolderList(0, null);
    try {
      if (name.equals("")) {
        json.getErrors().put("name", "目录名称不能为空");
      }
      if (ename.equals("")) {
        json.getErrors().put("ename", "英文名称不能为空");
      } else {
        for (Folder folder : list) {
          if (folderId != folder.getFolderId()) {
            if (ename.equals(folder.getEname())) {
              json.getErrors().put("folderEname", "英文名称不能重复");
            }
          }
        }
      }

      // 检测校验结果
      validate(json);
      String newEname = ename.toLowerCase();
      folderService.updateFolderById(folderId, newEname, name, content);

      json.setResult(true);
    } catch (Exception e) {
      json.setResult(false);
      json.setMsg(e.getMessage());
    }
    return json;
  }