(一)首先引用c标签:<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
(二)其次,引用标签后,即可使用。
(1)关于 if 的操作:
如果emp.gender等于0的时候,则显示为女,否则则显示男
在java语句中:if (emp.gender ==0) 显示 '女' else 显示 '男'
方法一:在Jstl语句中:(没有else,可以用双层if)
<c:if test="${emp.gender==0}">
女
</c:if>
<c:if test="${emp.gender!=0}">
男
</c:if>
方法二:另一种方法:
${emp.gender==0?'女':'男'}
方法三:使用when,判断
<%--方法二: --%>
<c:choose>
<c:when test="${emp.gender==0}">
女生啊
</c:when>
<c:otherwise>
男生啦
</c:otherwise>
</c:choose>
详细例子:
<c:if test="${not empty requestScope.employeeList}">
<table border="1" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>LastName</th>
<th>EMail</th>
<th>Gender</th>
<th>DepartmentName</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<c:forEach items="${requestScope.employeeList}" var="emp">
<tr>
<td>${emp.id}</td>
<td>${emp.lastName}</td>
<td>${emp.email}</td>
<td> ${emp.gender==0?'女':'男'}
<c:if test="${emp.gender==0}">
女
</c:if>
<c:if test="${emp.gender!=0}">
男
</c:if>
</td>
<td>${emp.department.departmentName}</td>
<td><a href="#">编辑</a></td>
<td><a href="#">删除</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
(2)empty使用
用来对一个空变量值进行判断: null、一个空String、空数组、空Map、没有条目的Collection集合
例子:
(1)当链表不为空的时候
<c:if test="${not empty requestScope.employeeList}">
当链表不为空的时候
</c:if>
(2)当链表为空的时候
<c:if test="${not empty requestScope.employeeList}">
当链表不为空的时候
</c:if>
(3)调用显示链表中 : 对象的属性
链表中的部门表的部门名称: (链表.对象.属性)
<td>${emp.department.departmentName}</td>
截图如上