1.EL表達式 獲取list長度
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:if test="${fn:length(list名字)>1}"> 中間該干嘛干嘛 </c:if>
2.不用循環,EL在List中直接獲取第一項的內容
${list[0].屬性}
3.EL獲取Map的鍵,Map的值
<c:forEach items="${map名字}" var="k"> <option value="${k.key }">${k.value}</option> </c:forEach>
這樣分別獲取鍵和值。
4.<c:if test="條件是相等或不想等"> 情況說明
【注意】:如果遇到 == 不起作用,使用eq看是否起作用,一般情況下==可以滿足任何類型的比較
首先,頁面最上引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
接着,在頁面模擬一個數據,不用從后台傳過來,不用那么麻煩了
①int值比較是否相等
<%int a = 12;request.setAttribute("a", a); %> <c:if test="${a eq 12}"> 該干嘛干嘛 </c:if>
或者
<%int a = 12;request.setAttribute("a", a); %> <c:if test="${a == 12}"> 該干嘛干嘛 </c:if>
②int值比較不相等
<%int a = 12;request.setAttribute("a", a); %> <c:if test="${a != 12}"> 該干嘛干嘛 </c:if>
③Integer值比較相等
<%Integer a = 12;request.setAttribute("a", a); %> <c:if test="${a eq 12}"> 該干嘛干嘛 </c:if>
或者
<%Integer a = 12;request.setAttribute("a", a); %> <c:if test="${a == 12}"> 該干嘛干嘛 </c:if>
④Integer值比較不相等
<%Integer a = 12;request.setAttribute("a", a); %> <c:if test="${a != 12}"> 該干嘛干嘛 </c:if>
⑤String值比較相等【注意,單引號或者雙引號的問題】
<%String a = "涼涼";request.setAttribute("a", a); %> <c:if test="${a eq '涼涼'}"> 涼涼夜色思念為你成河 </c:if>
或
<%String a = "涼涼";request.setAttribute("a", a); %> <c:if test="${a == '涼涼'}"> 涼涼夜色思念為你成河 </c:if>
⑥String值比較不想等
<%String a = "涼涼";request.setAttribute("a", a); %> <c:if test="${a != '涼涼'}"> 涼涼夜色思念為你成河 </c:if>
5.El表達式判空操作
<c:if test="${empty admin.name}">
或者
<c:if test="${not empty admin.name}">