万能的HashMap

万能的HashMap:如果有有函数要把一个整变量total,和记录集List返回,本来想定义为这种样子:
 Map<Integer,List<Record>> getEmpInfoList(String orgId,int page,int rows){}
这样可以返回map,但在调用后要取出里面的内容,就得用json形式来解析,好麻烦,这时,就可以用Map<String,Object>来定义,
再根据key来取出里面的内容,好方便...
 //根据orgId查询持证台帐信息
 Map<String,Object> getEmpInfoList(String orgId,int page,int rows){
  Record rCount=RecordService.findFirst("select count(1) as total from("+sql+")");
  int total=Integer.parseInt(rCount.get("TOTAL").toString());
  List<Record>rlist=RecordService.find(sql);
  
  Map<String,Object> map=new HashMap<String,Object>();
  map.put("total",total);
  map.put("rlist", rlist);
  return map;
 }
  而在调用时,用强制转换就可以取得到相应的东东:
  Map<String,Object> mapInfo=getEmpInfoList(orgId,page,rows);
  int total=(Integer)mapInfo.get("total");
  List<Record>rlist=(List<Record>)mapInfo.get("rlist");

猜你喜欢

转载自blog.csdn.net/c_huabo/article/details/51452747