常用JSTL标签

1、判断是否为空

<c:choose>
    <c:when test="${not empty reportInfo.user_register_orgs.register_orgs_statistics}">
        <tr>
            <td>${reportInfo.user_register_orgs.register_orgs_statistics.count}</td>
            <td>${reportInfo.user_register_orgs.register_orgs_statistics.label}</td>
        </tr>
    </c:when>
</c:choose> 

2、根据条件判断

<c:choose>
    <c:when test="${reportInfo.user_gray.has_report == '1'}"></c:when>
    <c:otherwise></c:otherwise>
</c:choose>

3、json循环

<c:choose>
    <c:when test="${not empty reportInfo.user_idcard_suspicion.idcard_with_other_phones}">
        <c:forEach items="${reportInfo.user_idcard_suspicion.idcard_with_other_phones}" var="ruisiwop" varStatus="vs">
            <tbody>
                <tr class="tc">
                    <td>${ruisiwop.susp_phone}</td>
                    <td>${ruisiwop.susp_phone_operator}</td>
                    <td>${ruisiwop.susp_phone_province}/${ruisiwop.susp_phone_city}</td>
                    <td>${ruisiwop.susp_updt}</td>
                </tr>
            </tbody>
        </c:forEach>
    </c:when>
</c:choose> 

4、数字显示百分数

<fmt:formatNumber type="percent" value="${reportInfo.user_gray.contacts_number_statistic.pct_cnt_to_black}" />

5、日期格式化


(1)jstl标签中的日期格式输出

在jsp页面中使用jstl标签将long型的时间戳转换为格式化后的时间字符串

1.通过<jsp:useBean /> 导入java.util.Date类
2.通过<jsp:setProperty />为Date实例设置long型 time属性值
3.通过<fmt:formatDate />格式化Date实例

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<jsp:useBean id="dateValue" class="java.util.Date"/>
<jsp:setProperty name="dateValue" property="time" value="${timestampValue}"/>
<fmt:formatDate value="${dateValue}" pattern="MM/dd/yyyy HH:mm"/>

(2)JSTL 格式化时间戳,比如 1427264998586 怎么显示成 2015-03-25 02:29:58 如此类格式呢?看以下的代码吧:

<jsp:useBean id="myDate" class="java.util.Date"/> 
<c:set target="${myDate}" property="time" value="${obj.date}"/> 
<fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${myDate}" type="both"/> 

需要导入包:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

 

posted @ 2018-01-11 16:32  Geek仁杰  阅读(503)  评论(1编辑  收藏  举报