Java 如何按组显示数据?
我正在尝试从不同的表加载订单数据 我还使用Java 如何按组显示数据?,java,jsp,Java,Jsp,我正在尝试从不同的表加载订单数据 我还使用JOINquery显示了来自表的数据 这是我的订单: 我想要这样的东西: 如果重复,此处的订单ID即编号应显示一次 我的JSP代码: <table class="table table-condensed"> <% List<String> oIdList = (List<String>)request.g
JOIN
query显示了来自表的数据
这是我的订单:
我想要这样的东西:
如果重复,此处的订单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>
不
品名
产品数量
订货时间
订单状态
将变量LASTIDDISPLAY设置为循环中每次显示的id(将其初始化为-1或其他无效)。如果lastiddisplated==id,则不显示id。您的示例不是非常面向对象的。您应该将所有这些字符串数组列表转换为顺序对象
然后对订单进行迭代(首先使用可比较的接口对订单进行排序,然后比较订单id值)
然后使用一些基本逻辑检查最后一个订单id值是否与最后一个相同。您好。伙计。试试这个
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>
for(int j=0,i=0;i
您可以添加一个Jquery代码,如果该编号列中有多行相同,则将值更改为空。我已更正了下面的代码。先生,我可以打印i值吗?即,在11处为1,然后在9处为2,在7处为3。当然。打印i值:但是,先生,当我在这两种情况下使用
时,它会给我类似0,1,…,4,。
,我想要像1,2,…,3。
我已经修改了这一行的(int j=0,I=0;I