public Map<Order,Items[]> findOrderInfo(int id){ //将多表查询信息的一记录封装到一个map中 CustomerDaoImp cdi =new CustomerDaoImp(); Map<Order,Items[]> map = new HashMap<Order,Items[]>(20); Order order =new Order(); //封装订单的头信息 Items[] its = new Items[20]; //数组装有多个商品,及对应数量。Items有fg,和count属性对应商品和数量 try { PreparedStatement pst = DbConn.getConnection().prepareStatement("select * from order_info o join Order_goods_1 g on o.id=g.id where o.id=?"); pst.setInt(1, id); ResultSet rs =pst.executeQuery(); if(rs.next()){ order.setOnum(rs.getString("onum")); order.setOname(rs.getString("oname")); order.setOcardnum(rs.getString("ocardnum")); order.setOaddr(rs.getString("oaddr")); order.setOphone(rs.getString("ophone")); order.setCost(rs.getInt("cost")); order.setTime(rs.getTimestamp("crea_at")); order.setInfo(rs.getString("oinfo")); for (int i = 1; i < its.length+1; i++) { //此循环获取数量不是0的商品 Items it =new Items(); byte m =rs.getByte("goods"+i); it.setCount(m); if(m>0){ int j =0; it.getFg().setName(cdi.findNameById(i)); it.getFg().setPrice(cdi.findPriceById(i)); it.getFg().setSpec(cdi.findSpecById(i)); its[j]=it; j++; } } map.put(order, its); } } catch (SQLException e) { System.out.println("com.jdc.dao.ManagerDao.java"); } return map; }}
添加回答
举报
0/150
提交
取消