gpt4 book ai didi

java - JSP - 当值重复时如何打印出空的 ?

转载 作者:行者123 更新时间:2023-11-30 11:19:30 25 4
gpt4 key购买 nike

下面我有打印出第一张图片的 JSP 代码。我正在努力实现第二张图片中的内容。

我总共有 8 列。只要有来自内部连接表的数据,前 4 列就会打印出来,其中包括数据会发生变化的最后 4 列。我希望打印出从上面复制信息的列和行中的空数据或空间。每个 ID 最多可以有 6 行(最左边的列)。

<table border="1" width="100%">
<tr>
<th>Student ID</th>
<th>Last Name</th>
<th>First Name</th>
<th>Grade</th>
<th>Events</th>
<th>Participation Level</th>
<th>Ind/Team</th>
<th>Event Name</th>
</tr>

<c:forEach var="row" items="${result.rows}">


<% theStudentId = 123 ; %>
<% System.out.println("at " + (new java.util.Date()) + ", theStudentId is " + theStudentId); %>

<tr>
<td><c:out value="${row.idStudents}"/></td>
<td><c:out value="${row.LastName}"/></td>
<td><c:out value="${row.FirstName}"/></td>
<td><c:out value="${row.Grade}"/></td>
<td><c:out value="${row.idEvents}"/></td>
<td><c:out value="${row.Grade}"/></td>
<td><c:out value="${row.Type}"/></td>
<td><c:out value="${row.Name}"/></td>
</tr>

</c:forEach>

这是 jsp 目前打印出来的内容。

current

这就是我想要实现的。

target

最佳答案

您需要跟踪最后一个值。就在这部分之前:

<c:forEach var="row" items="${result.rows}">

您应该创建一个名为 lastStudentId 的变量(初始值为 null)。

在循环内部,检查当前学生 ID 是否等于 lastStudentId。 (我不知道该怎么做,因为您没有为这些字段提供类型信息,我假设它们是字符串)。如果它与上一个相同,则打印空的 td(例如,包含一个  )。如果不一样,则执行您通常执行的操作。

在循环的底部,分配 lastStudentId = row.idStudents 就可以了。

关于java - JSP - 当值重复时如何打印出空的 <td>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23200773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com