Java 数据库JSTL中包含10行的表

Java 数据库JSTL中包含10行的表,java,jstl,Java,Jstl,我想制作一个包含数据库数据的10行表。例如,如果我的数据库中有5条记录,那么表中应该有5行数据和5行空行。我使用JSTL foreach: <c:forEach items="${foo}" var="f"> <tr> <td class="center aligned">${f.somethingId}</td>

我想制作一个包含数据库数据的10行表。例如,如果我的数据库中有5条记录,那么表中应该有5行数据和5行空行。我使用JSTL foreach:

               <c:forEach items="${foo}" var="f">

                    <tr>
                        <td class="center aligned">${f.somethingId}</td>
                        <td class="center aligned">${f.somethingName}</td>
                        <td class="center aligned">${f.somethingDescription}</td>
                    </tr>
               </c:forEach>

${f.somethingId}
${f.somethingName}
${f.somethingDescription}
对于数据库中的3条记录,我应该得到如下结果:


如何以最简单的方式创建它?

您可以运行
c:forEach
直到
10
(分别为索引9),并检查
foo
的列表大小是否小于或等于当前索引。如果是,则加载元素及其值,否则渲染空行元素:

<c:forEach var="i" begin="0" end="9">
    <h:panelGroup rendered="#{foo.size <= i}">
        <tr>
            <td class="center aligned">${foo.get(i).somethingId}</td>
            <td class="center aligned">${foo.get(i).somethingName}</td>
            <td class="center aligned">${foo.get(i).somethingDescription}</td>
        </tr>
    </h:panelGroup>
    <h:panelGroup rendered="#{foo.size > i}">
        <tr><td></td><td></td><td></td></tr>
    </h:panelGroup>
</c:forEach>

${foo.get(i).somethingId}
${foo.get(i).somethingName}
${foo.get(i).somethingDescription}

使用另一个循环,从
${foo.length}
循环到
10