EL表达式多条件判断方式

 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>

 

posted @ 2018-01-26 16:53  夜旦  阅读(7412)  评论(0编辑  收藏  举报