gpt4 book ai didi

java - Response.entity().build 未返回所有结果

转载 作者:行者123 更新时间:2023-12-02 03:20:54 26 4
gpt4 key购买 nike

我从 sql 检索数据并将其存储在列表中。然后我将其转换为 GenericEntity 并尝试使用 response.entity().build(); 返回它但它只返回第一项。

我确认该列表包含所有项目。所以问题应该是列表到实体的转换和/或响应的返回。我尝试循环响应部分,但没有成功。

List list = new ArrayList<>(); String stmt = ""; PreparedStatement ps; Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/islandfurniture-it07?zeroDateTimeBehavior=convertToNull&user=root&password=12345");

        if (countryID == null) {
stmt = "SELECT i.ID as id, i.NAME as name, f.IMAGEURL as imageURL, i.SKU as sku, i.DESCRIPTION as description, i.TYPE as type, i._LENGTH as length, i.WIDTH as width, i.HEIGHT as height, i.CATEGORY as category FROM itementity i, furnitureentity f where i.ID=f.ID and i.ISDELETED=FALSE and i.CATEGORY=?;";
ps = conn.prepareStatement(stmt);
ps.setString(1, category);
} else {
stmt = "SELECT i.ID as id, i.NAME as name, f.IMAGEURL as imageURL, i.SKU as sku, i.DESCRIPTION as description, i.TYPE as type, i._LENGTH as length, i.WIDTH as width, i.HEIGHT as height, i.CATEGORY as category, ic.RETAILPRICE as price FROM itementity i, furnitureentity f, item_countryentity ic where i.ID=f.ID and i.ID=ic.ITEM_ID and i.ISDELETED=FALSE and ic.COUNTRY_ID=? and i.CATEGORY=?;";
ps = conn.prepareStatement(stmt);
ps.setLong(1, countryID);
ps.setString(2, category);
}
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Furniture f = new Furniture();
f.setId(rs.getLong("id"));
f.setName(rs.getString("name"));
f.setImageUrl(rs.getString("imageURL"));
f.setSKU(rs.getString("sku"));
f.setDescription(rs.getString("description"));
f.setType(rs.getString("type"));
f.setWidth(rs.getInt("width"));
f.setHeight(rs.getInt("height"));
f.setLength(rs.getInt("length"));
f.setCategory(rs.getString("category"));
if (countryID != null) {
f.setPrice(rs.getDouble("price"));
}
list.add(f);
}

GenericEntity<List<Furniture>> entity = new GenericEntity<List<Furniture>>(list) {
};

return Response
.status(200)
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Headers", "origin, content-type, accept, authorization")
.header("Access-Control-Allow-Credentials", "true")
.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD")
.header("Access-Control-Max-Age", "1209600")
.entity(entity)
.build();

预期结果:显示所有家具元素。实际结果:显示第一个家具项目。

最佳答案

显示Response类代码可能更清晰..

关于java - Response.entity().build 未返回所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56927290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com