日期:2014-05-19 浏览次数:20818 次
while(rs.next()){ String stc=""; obj = new QueryObject(); obj.setLh(rs.getString("lh")); obj.setPm(rs.getString("pm")); obj.setGg(rs.getString("gg")); obj.setGysh(rs.getString("gysh")); obj.setSl(rs.getString("shl")); obj.setDanj(rs.getString("danj")); obj.setZongj(rs.getString("zongj")); obj.setUnit(rs.getString("unit")); obj.setCplb(rs.getString("lbl")); obj.setDate(rs.getString("indate")); //要在下面判断我上面的数组数据是否与下面的stc为一样为一样的就存到map里面 //MAP的key为数组参数 value为下面的list 这样怎么判断好? //sql 进行了ORDER by lb asc stc=rs.getString("lb"); System.out.println(stc); obj.setCplb(stc); list.add(obj); }
HashMap<String, List<QueryObject>> results = new HashMap<String, List<Object>>(); // KEY:lb // VALUE:QueryObject while (rs.next()) { String stc = ""; obj = new QueryObject(); obj.setLh(rs.getString("lh")); obj.setPm(rs.getString("pm")); obj.setGg(rs.getString("gg")); obj.setGysh(rs.getString("gysh")); obj.setSl(rs.getString("shl")); obj.setDanj(rs.getString("danj")); obj.setZongj(rs.getString("zongj")); obj.setUnit(rs.getString("unit")); obj.setCplb(rs.getString("lbl")); obj.setDate(rs.getString("indate")); obj.setCplb(rs.getString("lb")); List<Object> list = null; if (results.containsKey(obj.getCplb())) { list = results.get(obj.getCplb()); } else { list = new ArrayList<Object>(); results.put(obj.getCplb(), list); } list.add(obj); }