如果第一行已填充 Java,如何让每个对象有一列并添加另一行

How to have a column with each object and add another row if the first row is filled in Java

我正在使用 MySQL 编写 Java Servlet。我想以每行有五列的方式显示数据。这就是我想要的table。

目前,我有六个数据项,我将它们放在列表中,因此每个列表中有 5 个项目。 [a,b,c,d,e] , [f]

这是我目前拥有的table。我不确定如何以我想要的方式显示每个项目。

        //getting sql data
        List<Object> dataItems = new ArrayList<Object>();
        while (rset.next()) {
            SQLData item = new SQLData(rset.getString("name"), rset.getString("prod_desc"),
                    rset.getDouble("price"));
            dataItems.add(item);
        }

        //chuck list
        int size = 5;
        List<Object>[] partition = partition(dataItems, size);

        out.println("<div class='container' style='border:1px solid #cecece;'>");

        out.println("<div class='row'>");
        for (Object item : partition) {
            out.println("<div class='col'>");
            out.println("<p>" + item + " test </p>");
            out.println("</div>");
        }
        out.println("</div>");

        out.println("</div>");

有人可以帮忙吗?

这是演示代码。它将在 Servlet 或 JSP.

中工作
    List<String> dataItems = List.of("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p");
    out.println("<table>");
    out.println("<tr>");
    for (int i = 0; i < dataItems.size(); i++) {
        if(i >= 5 && i % 5 == 0){
            out.println("</tr><tr>");
        }
        out.println("<td> " + dataItems.get(i) + " </td>");
    }
    out.println("</tr>");
    out.println("</table>");