这是我使用 jdbc.webshopProducts 完成的查询是地图。
StringBuilder queryString=new StringBuilder();
queryString.append(" select cpm.name,cpm.catalogueprice,cpm.catalogueno ");
queryString.append(" from customer_product_master cpm ");
queryString.append(" where cpm.catalogueno in (?) ");
stmt=con.prepareStatement(queryString.toString());
stmt.setString(1,StringUtils.join(webshopProducts.keySet(),','));
rs=stmt.executeQuery();
webshopProductList=new ArrayList<WebshopProductVO>();
while(rs.next()){
WebshopProductVO webshopProduct=new WebshopProductVO();
webshopProduct.setArticleno(rs.getInt("catalogueno"));
webshopProduct.setName(rs.getString("name"));
webshopProduct.setPrice(rs.getFloat("catalogueprice"));
webshopProduct.setQuantity(webshopProducts.get(rs.getInt("catalogueno")));
webshopProduct.setSum(rs.getFloat("catalogueprice")*webshopProducts.get(rs.getInt("catalogueno")));
webshopProductList.add(webshopProduct);
}
我使用 StringUtils.join(webshopProducts.keySet(),',') 生成一个逗号分隔的整数列表。我面临的问题是,当地图中有多个值时,只有一个 WebshopProductVO 被添加到webshopProductList 即使有很多。