empty
格式:
${ empty 对象 } 返回结果为Boolean值
只要满足下面三个条件都返回true
1.对象是否为null
2.字符串是否为””
3.集合长度是否为0
关键代码
<!-- 特殊运算符 -->
<h1>执行特殊运算符</h1>
<%
//向请求域中设置属性
request.setattribute("str", null);
request.setAttribute("str1", "");
//创建4个集合
List list1=new ArrayList();
List list2=new ArrayList();
List list3=new ArrayList();
List list4=new ArrayList();
//向集合list2,list3,list4添加数据
list2.add("");
list3.add(null);
list4.add("abc");
//将集合放入到请求域中
request.setAttribute("list1", list1);
request.setAttribute("list2", list2);
request.setAttribute("list3", list3);
request.setAttribute("list4", list4);
%>
<!-- 满足条件1 -->
${empty str }<br>
<!-- 满足条件2 -->
${empty str1 }<br>
<!-- 满足条件3 -->
${empty list1 }<br>
<!-- 下面3个集合的长度都不为0 -->
${empty list2 }<br>
${empty list3 }<br>
${empty list4 }<br>
完整代码
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 特殊运算符 -->
<h1>执行特殊运算符</h1>
<%
//向请求域中设置属性
request.setAttribute("str", null);
request.setAttribute("str1", "");
//创建4个集合
List list1=new ArrayList();
List list2=new ArrayList();
List list3=new ArrayList();
List list4=new ArrayList();
//向集合list2,list3,list4添加数据
list2.add("");
list3.add(null);
list4.add("abc");
//将集合放入到请求域中
request.setAttribute("list1", list1);
request.setAttribute("list2", list2);
request.setAttribute("list3", list3);
request.setAttribute("list4", list4);
%>
<!-- 满足条件1 -->
${empty str }<br>
<!-- 满足条件2 -->
${empty str1 }<br>
<!-- 满足条件3 -->
${empty list1 }<br>
<!-- 下面3个集合的长度都不为0 -->
${empty list2 }<br>
${empty list3 }<br>
${empty list4 }<br>
</body>
</html>
结果展示
相关阅读
(-215:Assertion failed) !_src.empty() in function
(-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' Traceback (most recent call last):File "E:/project/cv_