【JSTL】 沒有else的解決方法


后台封裝了一個對象 放在model里:

model.addAttribute("notice", notice);

notice是個對象

 

然后前台如果沒有公告的話,希望顯示暫無公告:

 

前台<c:if>沒有else的邏輯,怎么解決?

 

解決方案:

 <div class="panel-body">
                   <c:choose>

                       <c:when test="${notice != null}">   
                            <h2 style = "text-align: center;">${notice.noticeName}</h2>
                           <h4 style = "text-align: center;">公布人:${notice.noticeCre}</h4>
                           <h4 style = "text-align: center;">公布日期:${noticeTime}</h4>
                           <br>
                           <div style = "text-align: center;">
                               ${notice.noticeContent}
                           </div>
                       </c:when>
                       <c:otherwise>  
                           <h2 style = "text-align: center;">暫無公告</h2>
                       </c:otherwise>
  
                </c:choose>
                   
          </div>

如此,有公告的時候,就顯示,沒有就是暫無公告:

 


免責聲明!

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



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