• 今天愣了半天硬是没想到用map,在此还原以下代码


        /**
         * 左边为项目类型,树结构的,需要将项目的树结构目录加上项目名拼接在一起,不同的项目做成下拉列表
    */ @Transactional(readOnly = false) public List<Map<String,Object>> findFullName(){
    //获取所有的父id和项目名称 List
    <ProjectInfo> list=projectInfoDao.findParentIdsAndProjectName();
    //定义一个list,泛型为map List
    <Map<String,Object>> fullNameList=new ArrayList<Map<String,Object>>(); for (ProjectInfo projectInfo : list) {
    //获取所有项目类型的父节点 String parentIds
    =projectTypeService.get(projectInfo.getProjectTypeId()).getParentIds();
    //获取本项目的项目类型 String ptName
    = projectTypeService.get(projectInfo.getProjectTypeId()).getName();
    //获取本项目名称 String projectName
    =projectInfo.getProjectName();
    //拆分父节点 String [] pId
    =parentIds.split(","); StringBuffer fullName=new StringBuffer(); Map<String,Object> map = new HashMap<String,Object>(); for (String str : pId) { if (!"0".equals(str)) {
    //通过父节点项目类型名称 String proTypeName
    =projectTypeService.get(str).getName();
    //拼接父节点 fullName
    =fullName.append(proTypeName+"--"); } }
    //在外层循环拼接本次项目类型名称和项目名称
    fullName.append(
    "--"+ptName).append("--"+projectName);
              //数据库设计存放的是projectId,没fullName,fullName只是在前台展示,
    //因此在form变单save的时候fullName必须与所属项目id保持一致,将id传到后台
    map.put("fullname", fullName); map.put("id",projectInfo.getId()); fullNameList.add(map); } return fullNameList; }

    前端也就很好写了

    <div class="control-group">
         <label class="control-label">所属项目:</label>
          <div class="controls">
             <form:select path="projectId" class="input-xlarge">
                 <c:forEach var="fullName" items="${fullNames}">
                             <option value="${fullName.id}" selected>
                                ${fullName.fullname}
                             </option>
                         </c:forEach> 
            </form:select>
          </div>
    </div>

    好了ok

    树结构的
  • 相关阅读:
    [LeetCode] 310. Minimum Height Trees
    [LeetCode] 722. Remove Comments
    [LeetCode] 243, 244, 245. Shortest Word Distance I, II, III
    [LeetCode] 939. Minimum Area Rectangle
    [LeetCode] 135. Candy
    [LeetCode] 1395. Count Number of Teams
    [LeetCode] 673. Number of Longest Increasing Subsequence
    [LeetCode] 724. Find Pivot Index
    [LeetCode] 1219. Path with Maximum Gold
    [LeetCode] 849. Maximize Distance to Closest Person
  • 原文地址:https://www.cnblogs.com/person008/p/7061996.html
Copyright © 2020-2023  润新知