【发布时间】:2021-07-10 14:55:22
【问题描述】:
我正在做的是实现一个表格来显示即将到来的约会,我有一个 if 语句,我希望在其中实现以防止显示旧的且不在当前时间范围内的数据。例如,约会前的昨天或几周不应显示在 jsp 中?
我教过一个 if 语句,目前的代码是:
<form method="POST" action="<%=request.getContextPath()%>/Appointment/delete">
<c:choose>
<c:when test="${empty list}">
<h1>No appointments available</h1>
</c:when>
<c:otherwise>
<table class="styled-table" style="margin-bottom: 15px; margin-top:15px;">
<thead>
<tr>
<th>Patient Name</th>
<th>Appointment Date</th>
<th>Delete</th>
</tr>
</thead>
<c:forEach items="${list}" var="record">
<c:choose>
<c:when test="${record.date lt} <% LocalDateTime now = LocalDateTime.now(); %>">
<tbody>
<tr class="active-row">
<td>${record.name}</td>
<td>${record.date}</td>
<td id="id"><button class="delete" value="${record.appointmentId}" ><i class="fas fa-trash-alt"></i></button></a></td>
</tr>
</tbody>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
</c:forEach>
</table >
</form>
嗯,我对学习 jsp 和 java web 开发的东西还是很陌生,我真的很感激帮助你完成这项工作。提前致谢。
【问题讨论】:
-
好吧,您已经在使用 JSTL(例如
<c:choose>等),所以<c:if>也应该可用。 -
请注意,
<% LocalDateTime now = LocalDateTime.now(); %>在表达式中不起作用。试试${record.date lt java.time.LocalDateTime.now()}之类的东西(不记得确切的 Java EL 语法 atm)。 -
谢谢大家的帮助