@RequestMapping(Constants.MV_URI_COMM_TREE + "/{from}") public ModelAndView tree(@PathVariable String from, HttpServletRequest request) { ModelAndView mv = new ModelAndView(); mv.addObject("from", from); mv.addObject(Constants.MV_OBJECT_APP, "core"); mv.setViewName(ROOT_VIEW + Constants.SYM_PATH_SEPARATOR + Constants.MV_VIEW_TREE); // 判断html树文件是否存在 不存在就生成 String htmlFile = getAppRoot(request) + Constants.STATIC_PATH + Constants.TREE_HTML_DEPT; if (!FileUtils.isFileExist(htmlFile)) { createCategoryTreeHtml(request); } return mv; }
/** * @Description:生成tree html * * @author:[email protected] * @date:2011-9-5 */ public void createCategoryTreeHtml(HttpServletRequest request) { List<AdminDept> entitys = adminDeptService.findByProperty("parentId", 0); String objName = "所有分类"; StringBuffer sb = new StringBuffer(); sb.append("<li href='#' id='0'"); sb.append("<a target='main'>" + objName + "</a><ul>"); for (AdminDept entity : entitys) { List<AdminDept> entitysOne = adminDeptService.findByProperty("parentId", entity.getId()); if (entitysOne.size() > 0) { sb.append( "<li href='#' id='" + entity.getId() + "'><a target='main'>" + entity.getName() + "</a><ul>"); for (AdminDept entityOne : entitysOne) { // sb.append("<li href='#' id='" + entityOne.getId()+"'><a target='main'>" + // entityOne.getName() + "</a></li>"); List<AdminDept> entitysTwo = adminDeptService.findByProperty("parentId", entityOne.getId()); if (entitysTwo.size() > 0) { sb.append( "<li href='#' id='" + entityOne.getId() + "'><a target='main'>" + entityOne.getName() + "</a><ul>"); for (AdminDept entityTwo : entitysTwo) { List<AdminDept> entitysThree = adminDeptService.findByProperty("parentId", entityTwo.getId()); if (entitysThree.size() > 0) { sb.append( "<li href='#' id='" + entityTwo.getId() + "'><a target='main'>" + entityTwo.getName() + "</a><ul>"); for (AdminDept entityThree : entitysThree) { sb.append( "<li href='#' id='" + entityThree.getId() + "'><a target='main'>" + entityThree.getName() + "</a></li>"); } sb.append("</ul></li>"); } else { sb.append( "<li href='#' id='" + entityTwo.getId() + "'><a target='main'>" + entityTwo.getName() + "</a></li>"); } } sb.append("</ul></li>"); } else { sb.append( "<li href='#' id='" + entityOne.getId() + "'><a target='main'>" + entityOne.getName() + "</a></li>"); } } sb.append("</ul></li>"); } else { sb.append( "<li href='#' id='" + entity.getId() + "'><a target='main'>" + entity.getName() + "</a></li>"); } } sb.append("</ul></li>"); String htmlFile = getAppRoot(request) + Constants.STATIC_PATH + Constants.TREE_HTML_DEPT; FileUtils.writeFile(htmlFile, sb.toString()); }