List>相关

时间:2024-01-10 23:13:44

2016年8月6日13:53:00

---------------------------

List<Map<String, Object>> List集合新增列

则需要:

List<Map<String, Object>> list_new = new ArrayList<Map<String, Object>>();

//新建list集合对象,用于存储新的数据

for (Map<String, Object> map : list) {//list为数据库查询出来的数据
  Long jxjhid=Long.valueOf(map.get("jxjhid").toString());   //上面的是获取jxjh的值   String mc_new="";   if(jxjhid==1){     mc_new="计划";   }else{     mc_new="不计划";   }
  
  map.put("sfjh", mc_new);
  list_new .add(map);
}
//另外一种方式
//不要下面两行代码
List<Map<String, Object>> list_new = new ArrayList<Map<String, Object>>();  
list_new .add(map);
 

------------------------------

List<Map<String, Object>> List集合删除map中的某个元素

粒子:

List<Map<String, Object>> list_new = new ArrayList<Map<String, Object>>();
Map<String, Object> map1=new HashMap<String, Object>();
map1.put("ks", "01");
map1.put("js", "10");
list_new.add(map1);
Map<String, Object> map2=new HashMap<String, Object>();
map2.put("ks", "01");
map2.put("js", "10");
list_new.add(map2); for (Map<String, Object> map : list_new) {
map.remove("js");
}

List<Map<String, Object>> List集合修改map中的元素

粒子:

List<Map<String, Object>> list_new = new ArrayList<Map<String, Object>>();
Map<String, Object> map1=new HashMap<String, Object>();
map1.put("ks", "01");
map1.put("js", "10");
list_new.add(map1);
Map<String, Object> map2=new HashMap<String, Object>();
map2.put("ks", "01");
map2.put("js", "10");
list_new.add(map2); for (Map<String, Object> map : list_new) {
map.put("js","11");
}

List<Map<String, Object>> List集合查询数据库数据

//公司wh框架的使用方法
String sql="select * from jxap "
// + " left outer join (select jxjhid,ks from jxjh) jxjh on jxjh.jxjhid=jxap.jxjhid"
+ " where jxap.jlztm=51 and jxap.bjid=:bjid and jxap.jxjhid in(select jxjhid from jxjh where xqm=:xqm )";
SqlCommandImpl sci=new SqlCommandImpl(sql);
sci.setInt("bjid", bjid);
sci.setInt("xqm", xqm);
List<Map<String, Object>> list=gdba.selectAsMapList(sci,jxap);
//普通的框架
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
 // 关闭连接flag
boolean colseFlag = false;
// 打开DB链接
if (this.connection == null) {
this.connection = this.getDbConnection();
colseFlag = true;
}
PreparedStatement preStat = null;
preStat = this.connection.prepareStatement(sql);
ResultSet rs = null;
Map<String, Object> map = null; rs = preStat.executeQuery();
// 生成ResultSetMetaData
ResultSetMetaData rsMeta = preStat.getMetaData();
while (rs.next()) {
map = this.Result2Map(rs, rsMeta);
// 追加到list中
list.add(map);
}