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 | 存储格式化日志变量的范围 | 否 | 页面 |