我正在尝试从不同的表加载订单数据。
我还使用 JOIN
查询显示了表中的数据。
这是我的o/p:
我想要这样的东西:
订单 ID,即此处的编号,如果重复,应显示一次。
我的 JSP 代码:
<table class="table table-condensed">
<%
List<String> oIdList = (List<String>)request.getAttribute("oIdList");
List<String> pNameList = (List<String>)request.getAttribute("pNameList");
List<String> pQtyList = (List<String>)request.getAttribute("pQtyList");
List<String> pTimeList = (List<String>)request.getAttribute("pTimeList");
List<Boolean> pStatusList = (List<Boolean>)request.getAttribute("statusList");
%>
<thead>
<tr>
<th width="8%">No.</th>
<th width="23%">Product Name</th>
<th width="20%">Product Qty</th>
<th width="18%">Order Time</th>
<th width="22%"><div align="center">Order Status</div></th>
</tr>
</thead>
<tbody>
<%
for(int i = 0; i<pNameList.size(); i++)
{
%>
<tr>
<td><%= oIdList.get(i) %></td>
<td class="center"><%= pNameList.get(i) %></td>
<td class="center"><%= pQtyList.get(i) %></td>
<td class="center"><%= pTimeList.get(i) %></td>
<%
if(pStatusList.get(i))
{
%>
<td class="center"><div align="center"><span class="label label-success">Delivered</span></div></td>
<%
}
else
{
%>
<td style="text-align: center;" width="9%"><span class="label">Pending</span></td>
<%
}
%>
</tr>
<%
}
%>
</tbody>
</table>
请提出任何建议..
最佳答案
你好。伙伴。试试这个
for(int j =0,i = 0; i<pNameList.size(); i++) {
%> <tr> <%
if(i==0){
j++;
%> <td><%= j %></td> <%
}else if(oIdList.get(i) != oIdList.get(i-1)){
j++;
%> <td><%= j %></td> <%
}else{
%> <td></td> <%
}
%>
<td class="center"><%= pNameList.get(i) %></td>
<td class="center"><%= pQtyList.get(i) %></td>
<td class="center"><%= pTimeList.get(i) %></td>
关于java - 如何按组显示数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20704498/