c:forEach 標簽中遍歷map集合


c:forEach 標簽中遍歷map集合
轉自:《c:forEach 標簽中遍歷map集合》網址:https://blog.csdn.net/moxiaoya1314/article/details/53610378

后台代碼:

    Map<VoteQuestion, List<VoteOption>> map = new HashMap<VoteQuestion, List<VoteOption>>();//創建一個map集合
                        
                        List<VoteQuestion> lVoteQuestions = voteQuestionService.getVid(voteMainTitle.getVid()); //根據vid查詢遍歷
                        if(lVoteQuestions.size()>0 && lVoteQuestions!=null){
                            model.addAttribute("lVoteQuestions", lVoteQuestions);
                            
                            for (int j = 0; j < lVoteQuestions.size(); j++) {
                                VoteQuestion vQuestion = lVoteQuestions.get(j);
                                String qid = vQuestion.getQid(); //獲取題目表中的qid
                                
                                List<VoteOption> lOptions = voteOptionService.findQid(qid); //根據qid查詢遍歷VoteOption
                                if(lOptions.size()>0 && lOptions!=null){
                                    model.addAttribute("lOptions", lOptions);
                                }
                                map.put(vQuestion, lOptions);
                            }
                        }    
                        model.addAttribute("map", map);


前台代碼:

    <c:forEach items="${map}" var="m" varStatus="vq">  
                            <tr>
                                <td>${vq.count }</td>
                                <td>${fns:unescapeHtml(m.key.question)}
                                    <c:if test="${m.key.questionType!='問答' }">
                                         題目選項:
                                         <c:forEach items="${m.value}" var="vOption">
                                             <c:if test="${m.key.questionType eq '單選' }">
                                                <input type="radio" class="i-check">${vOption.title}
                                            </c:if>
                                            
                                            <c:if test="${m.key.questionType eq '多選' }">
                                                <input type="checkbox" class="i-check">${vOption.title}
                                            </c:if>
                                         </c:forEach>
                                     </c:if>
                                </td>
                                <td>
                                    <shiro:hasPermission name="vote:voteQuestion:edit">
                                        <a href="#"
                                            οnclick="openDialog2('修改題目信息', '${ctx}/vote/voteQuestion/form?id=${m.key.id}&vid=${voteMainTitle.vid}&isAdd=1','60%', '60%')"
                                            class="btn btn-success btn-xs"><i class="fa fa-edit"></i>
                                            修改</a>
                                    </shiro:hasPermission>
                                    <shiro:hasPermission name="vote:voteQuestion:del">
                                        <a href="${ctx}/vote/voteQuestion/delete?id=${m.key.id}&VoteID=${voteMainTitle.id}"
                                            οnclick="return confirmx('確認要刪除該題目信息嗎?', this.href)"
                                            class="btn btn-danger btn-xs"><i class="fa fa-trash"></i>
                                            刪除</a>
                                    </shiro:hasPermission></td>
                            </tr>
                        </c:forEach>



具體實現的其他方法代碼:

    <c:forEach items="${customerMap}" var="item">  
                    <option value="${item.key }"   
                    title="編碼:${item.value.customer_num },許可證號:${item.value.license_key },簡稱:${item.value.short_name },聯系地址:${item.value.contact_address },聯系電話:${item.value.contact_phone }">  
                    ${item.value.corporate_name }</option>  
                </c:forEach>


<c:foreach循環一個HashMap,map中的value為一個bean,頁面獲取key即key對應bean中的屬性,獲取value即value對應bean中的屬性

 

我的使用

  <c:forEach items="${preTipMap}" var="map" varStatus="vq">
            <c:forEach items="${map.value}" var="item">
                var planName = "${item.planNum}"; //計划名稱
              
                <c:if test="${map.key == 'inspectPlanList'}">
                    nextTime = "${item.nextTime}"; //下次巡檢/保養時間
                </c:if>
              
            </c:forEach>
        </c:forEach>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM