jsp技术之JSLT技术<c:if text="">判断

JSLT的c:if标签

作用:用来进行判断的

语法:

<c:if test="判断条件,使用EL表达式进行判断">
    如果判断为true,这里的内容会生效;如果为false,这里内容相当于不存在
</c:if>

案例

一.数值判断(单条件)

<c:if test="${age < 18}">
    <span style="color:red;">未成年</span>
</c:if>


<c:if test="${age >= 18}">
    <span style="color:green;">已成年</span>
</c:if>

<c:if test="${1 >= 18}">
    <span style="color:green;">未成年</span>
</c:if>

 

 二.判空处理(多条件逻辑判断)

判断是否为空
 

<c:if test="${empty str}"> str为空</c:if>

<c:if test="${not empty str}"> str不为空</c:if>

 

多条件逻辑判断

与(有假为假)
<
c:if test="${not empty str1 && not empty str2}"> str1不为空,str2不为空</c:if>
或(有真为真)
<c:if test="${not empty str1 || not empty str2}"> str1不为空,str2不为空</c:if>

三.判断比较的字符串

<%-- 如果     获取产品录入人缓存名称(字符串)  eq比较  获取缓存登录人姓名(字符串)  与  获取缓存登录人姓名(字符串)  eq比较 '字符串'   --%>
<c:if test="${app:fullname(product.userId) eq app:fullname(user.userId) || app:fullname(user.userId) == 'IT部负责人'}">
    执行体
</c:if>

 

四.判断布尔类型

 <c:set var="check" value="${file.checkDir}" scope="request"/>

<c:if test="${check==true}"> <td> <a href="showfiles.do?filename=${file.fileName}">${file.fileSingleName}</td> </c:if>

<c:if test="${check==false}"> <td> <a href="download.do?filename=${file.fileName}">${file.fileSingleName}</a></td> </c:if>

总结

  1.注意比较的值,如果两个都是从缓存中获取的也需要在一个${}符号里面,参考字符串比较

  2.比较的方式有很多,但要注意如果直接用字符串比较,声明的不是" "双引号,而是' '单引号

 

posted @ 2021-04-20 19:36  骚哥  阅读(1462)  评论(0编辑  收藏  举报