常用JSTL標簽
阿新 • • 發佈:2018-01-11
with repo property hone ref http sta 數字 otherwise
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" %>
常用JSTL標簽