java - 如何按组显示数据?

标签 java jsp

我正在尝试从不同的表加载订单数据。

我还使用 JOIN 查询显示了表中的数据。

这是我的o/p: enter image description here

我想要这样的东西:

enter image description here

订单 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/

相关文章:

java - Spring Boot 应用程序在 Heroku code=H10 上崩溃

java - 使用 Java URL 解析带有 unicode 字符的维基百科 url 时出错

eclipse - 如何在Eclipse中修改EL打开模板?

java - JSTL foreach - 使用特定字段对列表进行排序

json - 在许多 div + Struts2 中加载 JSON 的一部分

java - 聊天程序卡住 JFrame

java - Collection.stream() 是否有内部同步?

java - Action 类被调用两次

eclipse - Tomcat 7.0 : Integrate with Eclipse

java - 简单的java游戏: Filling up figures drawn by a moving cursor