后台封裝了一個對象 放在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>
如此,有公告的時候,就顯示,沒有就是暫無公告: