合并表行html

时间:2014-10-09 19:27:31

标签: java html jsp

我使用for循环创建了一个html表,它在jsp中动态创建表。

下面是一段代码。

Java for循环:

for(int i=0; i<mleFIPStepsInfo.size(); i++)
{
    Map map = (Map) mleFIPStepsInfo.get(i);

html代码:

    <tr>
    <td style="text-align: center;" rowspan=4><span style="font-size:13px;"><strong><span style="font-family:calibri;"><%=map.get("attribute[Sequence]")%>&nbsp;</td>

        <td style="text-align: center;"><span style="font-size:13px;"><strong><span style="font-family:calibri;"><%=map.get("name")%>&nbsp;</td>
        <td style="text-align: center;"><span style="font-size:13px;"><strong><span style="font-family:calibri;"><%=map.get("description")%>&nbsp;</td>
        <td style="text-align: center;"><span style="font-size:13px;"><strong><span style="font-family:calibri;"><%=map.get("attribute[Instructions]")%>&nbsp;</td>
    </tr>

现在我有10条记录。

对于前5个记录,序列号为1,其他记录为2,3,4,5,6。现在我正在尝试构建一个包含10行,我应该有前5行要合并,如下所示:

序列名称描述说明

        Name1   Description1    Instructions1
        Name2   Description2    Instructions2

1 Name3 Description3 Instructions3

        Name4   Description4    Instructions4
        Name5   Description5    Instructions5

2 Name6 Description6 Instructions6

3 Name7 Description7 Instructions7

4 Name8 Description8 Instructions8

5名称9说明9说明9

6名称10描述10说明10

我无法在StackOverflow中正确打印表格,但我基本上需要的是前5行需要与序列号1合并。

1 个答案:

答案 0 :(得分:0)

您希望前5行显示为一个非常长的行,您需要省略下一行具有相同序列号的每一行的关闭,并且对于其前一行具有相同序列号的每一行都打开。 / p>

类似的东西:

for(Map.Entry entry : map) {
   if(prevEntry != null && prevEntry.sequence != entry.sequence) {
      write("<tr>");
   }
   // Write the rest of the row here
   if(nextEntry != null && nextEntry.sequence != entry.sequence) {
      write("</tr>");
   }
}