Java add all table data into list

前端 未结 1 416
执笔经年
执笔经年 2021-01-24 09:55
+--------+-------+-----+
|  Name  |number |qty  |
+--------+-------+-----+
|   ab   |   5   |  7  |
+--------+-------+-----+ 
|   cd   |   1   |  6  |
+--------+-------+         


        
相关标签:
1条回答
  • 2021-01-24 09:59

    Make your search() method return a List<Product> instead of a single Product.

    public List<Product> search(){
        List<Product> products = new ArrayList<Product>();
        ResultSet rs = DAO.fetch("SELECT * FROM Products");
        while (rs.next()) {
            Product product = new Product();
            product.setNumber(rs.getString("ProductNumber"));
            product.setName(rs.getString("ProductName"));
            product.setQty(rs.getString("ProductQty"));
            products.add(product);
        }
        return products;
    }
    

    Then, in your JSP file, iterate over the returned list:

    <c:forEach var="product" items="${products}">
        <!-- build your row -->
    </c:forEach>
    
    0 讨论(0)
提交回复
热议问题