JSTL之浅析

JSTL(Java Standard Tag Library):java标准标签库

主要应用于WEB层,前台处理对象。

项目中最常用的是<c:if> ,<c:choose>,<c:when>,<c:otherwise>,<c:foreach>,当然也还有<c:out>等标签

①<c:if>就是判断分支,判断对象值是否符合分支要求,适合分支数目仅有一个或者两个  分支比较少的情况

例如:

<c:if test="${workShift.status eq '0'}">
           <a href="${ctx}/schedule/workShift/form?id=${workShift.id}&orgId=${workShift.orgId}">修改</a>
        <a href="${ctx}/schedule/workShift/delete?id=${workShift.id}&orgId=${workShift.orgId}" onClick="return confirmx('确定要删除该行政班次吗?', this.href)">删除</a> <!-- sun修改弹窗提示"确认要删除该班次定义吗?"为弹窗提示"确定要删除该行政班次吗?" -->
</c:if>


 ②<c:choose><c:otherwise><c:otherwise>  这三个标签可以放在一起来说,<c:choose>是后两者的父标签,也是判断分支,主要用于多分支比较  多种情况下用此三标签来进行分支判断筛选

例如:

 <c:choose>
               <c:when test="${workShift.beginTime.length() eq 1}">  0${workShift.beginTime}:00  </c:when>
               <c:when test="${workShift.beginTime.length() eq 2}">  ${workShift.beginTime}:00  </c:when>
               <c:when test="${workShift.beginTime.length() eq 3}">  0${workShift.beginTime.substring(0, 1)}:30  </c:when>
               <c:otherwise>${workShift.beginTime.substring(0,2)}:30 </c:otherwise>
</c:choose>

③<c:foreach>就是前台页面对象数据的遍历,var 代表前台遍历对象变量,item 代码后台传来的数据对象

代码:

<c:forEach items="${page.list}" var="workShift">
    <tr>
     <td>${fns:getDictLabel(workShift.workShiftType, 'schedule_admin_type', '')}</td>
     <td>${workShift.workShiftName}</td>
        <td>
        <c:choose>
               <c:when test="${workShift.beginTime.length() eq 1}">  0${workShift.beginTime}:00  </c:when>
               <c:when test="${workShift.beginTime.length() eq 2}">  ${workShift.beginTime}:00  </c:when>
               <c:when test="${workShift.beginTime.length() eq 3}">  0${workShift.beginTime.substring(0, 1)}:30  </c:when>
               <c:otherwise>${workShift.beginTime.substring(0,2)}:30 </c:otherwise>
        </c:choose>
     </td>
     <td>
     <c:choose>
            <c:when test="${workShift.endTime.length() eq 1}">  0${workShift.endTime}:00  </c:when>
               <c:when test="${workShift.endTime.length() eq 2}">  ${workShift.endTime}:00  </c:when>
               <c:when test="${workShift.endTime.length() eq 3}">  0${workShift.endTime.substring(0,1)}:30  </c:when>
               <c:otherwise>${workShift.endTime.substring(0, 2)}:30 </c:otherwise>
        </c:choose>
        </td>
     <td>${workShift.restHour eq .5 ? 0.5 : workShift.restHour}</td>
     <td>${workShift.workHour  eq .5 ? 0.5 : workShift.workHour}</td>
     <td>${workShift.remarks}</td>
     <shiro:hasPermission name="schedule:workShift:edit">
      <td>
       <c:if test="${workShift.status eq '0'}">
           <a href="${ctx}/schedule/workShift/form?id=${workShift.id}&orgId=${workShift.orgId}">修改</a>
        <a href="${ctx}/schedule/workShift/delete?id=${workShift.id}&orgId=${workShift.orgId}" onClick="return confirmx('确定要删除该行政班次吗?', this.href)">删除</a> <!-- sun修改弹窗提示"确认要删除该班次定义吗?"为弹窗提示"确定要删除该行政班次吗?" -->
       </c:if>
      </td>
     </shiro:hasPermission>
    </tr>

</c:forEach>

④其他标签以及常用:

<fmt:formatDate/>主要用来格式化时间

属性 描述 是否必要 默认值
value 要显示的日期
type DATE, TIME, 或 BOTH date
dateStyle FULL, LONG, MEDIUM, SHORT, 或 DEFAULT default
timeStyle FULL, LONG, MEDIUM, SHORT, 或 DEFAULT default
pattern 自定义格式模式
timeZone 显示日期的时区 默认时区
var 存储格式化日期的变量名 显示在页面
scope 存储格式化日志变量的范围 页面

<fmt:parseDate/>主要用来将字符串转为时间格式

属性 描述 是否必要 默认值
value 要显示的日期
type DATE, TIME, 或 BOTH date
dateStyle FULL, LONG, MEDIUM, SHORT, 或 DEFAULT default
timeStyle FULL, LONG, MEDIUM, SHORT, 或 DEFAULT default
pattern 自定义格式模式
timeZone 显示日期的时区 默认时区
var 存储格式化日期的变量名 显示在页面
scope 存储格式化日志变量的范围 页面


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值