示例#1
0
 /** 获取文件夹列表 */
 @RequestMapping("/folder/getFolders")
 @ResponseBody
 public List<TreeModel> getFolders(@RequestParam(value = "id", required = false) String id) {
   try {
     if (id == null || GUID.emptyID.toString().equals(id)) {
       TreeModel treeModel = new TreeModel();
       treeModel.setId(GUID.emptyID.toString());
       treeModel.setText("图片文件夹");
       treeModel.setState("open");
       AttributesModel attributesModel = treeModel.new AttributesModel();
       attributesModel.setCode("2");
       treeModel.setAttributes(attributesModel);
       List<TreeModel> list = new ArrayList<TreeModel>();
       list.add(treeModel);
       List<FolderVo> folderList = folderService.getFoldersByParentId(GUID.emptyID.toString());
       if (folderList == null || folderList.isEmpty()) {
         return list;
       }
       folderConventerToTreeModel(folderList);
       treeModel.setChildren(
           folderConventerToTreeModel(folderList).toArray(new TreeModel[folderList.size()]));
       return list;
     } else {
       List<FolderVo> folderList = folderService.getFoldersByParentId(id);
       return folderConventerToTreeModel(folderList);
     }
   } catch (Exception e) {
     e.printStackTrace();
     log.error("获取文件夹发生异常====" + e.getStackTrace());
   }
   return null;
 }
示例#2
0
 /** 将文件夹转换为对应的TreeModel */
 private List<TreeModel> folderConventerToTreeModel(List<FolderVo> folderList) {
   List<TreeModel> treeModelList = new ArrayList<TreeModel>();
   FolderVo folder;
   TreeModel treeModel;
   for (int i = 0; null != folderList && i < folderList.size(); i++) {
     folder = folderList.get(i);
     treeModel = new TreeModel();
     treeModel.setId(folder.getRecid());
     treeModel.setText(folder.getTitle());
     treeModel.setState(isHasNodes(folder.getRecid()));
     AttributesModel am = treeModel.new AttributesModel();
     am.setParentId(folder.getParentId());
     am.setCode(folderService.getFoldersByParentId(folder.getRecid()).size() < 1 ? "0" : "1");
     treeModel.setAttributes(am);
     treeModelList.add(treeModel);
   }
   return treeModelList;
 }
示例#3
0
 /** 判断节点是否有子节点 */
 private String isHasNodes(String id) {
   if (folderService.getFoldersByParentId(id).size() < 1) {
     return "open";
   }
   return "closed";
 }