所遇到的問題后端model傳入前端JSP頁面中的值通過foreach循環內要滿足條件才能取值給Div中,我們知道jsp頁面中可以直接用EL表達式取值,格式就是${"model中傳來的數據"},但是我要把傳過來的數據判斷后再取值就遇到了問題,通過查百度發現了一個方法,下面就分享一下。
1 <c:forEach var="v" items="${page.objectList}"> 2 <tr> 3 <td style="text-align: center;">${v.card}</td> 4 <td style="text-align: center;">${v.vehicleType.name}</td> 5 <td style="text-align: center;"> 6 <c:if test="${v.status==0}">完好</c:if> 7 <c:if test="${v.status==1}">良好</c:if> 8 <c:if test="${v.status==2}">輕度受損</c:if> 9 <c:if test="${v.status==3}">嚴重破損</c:if> 10 </td> 11 <td style="text-align: center;">${v.num}</td> 12 <td style="text-align: center;">${v.dept.name}</td> 13 <c:if test="${v.driver.driving==0}"> 14 <td style="text-align: center;">${v.driver.name}</td> 15 </c:if> 22 </tr> 23 </c:forEach>
if判斷的部分是在foreach中判斷
<c:if test="${v.driver.driving==0}"></c:if>
就是精髓所在,哈哈