jsp中的JSTL标签使用笔记(20170626)

(一)首先引用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>



截图如上



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值