1 <td> 2 <c:forEach items="${cityMap}" var="entry"> 3 <hr> 4 <input type="checkbox" class="chooseAll"><strong>${entry.key}</strong><br> 5 <hr> 6 <c:if test="${entry.key ne '澳門特別行政區'}"> 7 <c:if test="${entry.key ne '香港特別行政區'}"> 8 <c:if test="${entry.key ne '北京市'}"> 9 <c:if test="${entry.key ne '天津市'}"> 10 <c:if test="${entry.key ne '重慶市'}"> 11 <c:if test="${entry.key ne '上海市'}"> 12 <c:forEach items="${entry.value}" var="str"> 13 <input class="douc" type="checkbox" value="${str}" name="area">${str} 14 </c:forEach> 15 </c:if> 16 </c:if> 17 </c:if> 18 </c:if> 19 </c:if> 20 </c:if> 21 <br> 22 </c:forEach> 23 </td>
本想都寫在一個if里,如
2018-2-2 17:12:30
今天又改需求,因業務邏輯對城市部分進行調整,發現下面這種方式也可以。。。之前用這種方式出問題可能是由於某種不可抗力,mmp
1 <c:if test="${entry.key ne '澳門特別行政區' 2 ||entry.key ne '香港特別行政區' .... 3 }">
//事實證明這樣寫頁面會出問題
另補充一下,EL中的三目運算符使用
1 <span style="font-size: 8px">${item.sex==1?"男":"女"}</span><br>
繼續補充,因業務需要對el獲取中的值判斷是否包含某個字符串,網上搜了下,現整理一下
頁面中聲明:<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
函數 |
描述 |
fn:contains(string, substring) |
如果參數string中包含參數substring,返回true |
fn:containsIgnoreCase(string, substring) |
如果參數string中包含參數substring(忽略大小寫),返回true |
fn:endsWith(string, suffix) |
如果參數 string 以參數suffix結尾,返回true |
fn:escapeXml(string) |
將有特殊意義的XML (和HTML)轉換為對應的XML character entity code,並返回 |
fn:indexOf(string, substring) |
返回參數substring在參數string中第一次出現的位置 |
fn:join(array, separator) |
將一個給定的數組array用給定的間隔符separator串在一起,組成一個新的字符串並返回。 |
fn:length(item) |
返回參數item中包含元素的數量。參數Item類型是數組、collection或者String。如果是String類型,返回值是String中的字符數。 |
fn:replace(string, before, after) |
返回一個String對象。用參數after字符串替換參數string中所有出現參數before字符串的地方,並返回替換后的結果 |
fn:split(string, separator) |
返回一個數組,以參數separator 為分割符分割參數string,分割后的每一部分就是數組的一個元素 |
fn:startsWith(string, prefix) |
如果參數string以參數prefix開頭,返回true |
fn:substring(string, begin, end) |
返回參數string部分字符串, 從參數begin開始到參數end位置,包括end位置的字符 |
fn:substringAfter(string, substring) |
返回參數substring在參數string中后面的那一部分字符串 |
fn:substringBefore(string, substring) |
返回參數substring在參數string中前面的那一部分字符串 |
fn:toLowerCase(string) |
將參數string所有的字符變為小寫,並將其返回 |
fn:toUpperCase(string) |
將參數string所有的字符變為大寫,並將其返回 |
fn:trim(string) |
去除參數string 首尾的空格,並將其返回 |
頁面用法示例:
1 <c:choose>
2 <c:when test="${fn:contains(item.content,'你要判斷的值')}">
3 <img src="${item.content}" width="100px" height="100px"><br>
4 </c:when>
5 <c:otherwise>
6 <div width="100px" height="100px">
7 <span>${item.content}</span>
8 </div>
9 </c:otherwise>
10 </c:choose>