项目中后台查询字典切换显示内容

List list = companyDao.xyunitUserListByType(hash);

Map para = new HashMap();
para.put("Unit_type", "612");
para.put("Unit_nmtype", "601");
para.put("Class_type", "611");


para.put("Communication_methods_type", "207");
para.put("Unit_condition", "604");
para.put("Industry_categories", "99997");
list = listFormat(list, para);

 

//封装的方法==============

public List listFormat(List list,Mappara) {
if(null==list ||list.size()==0) {
return new ArrayList();
}
//获取list元素的类
Class c=list.get(0).getClass();
boolean flag=false;
//hashmap为真。实体类为false
if(c.equals(HashMap.class)) {
flag=true;
}

try {
//便利参数,获取需要替换的字段,以及按照的fid
for (String key : para.keySet()) {
String fid=para.get(key);
//redis 获取字典
List listResult= (List) RedisUtils.get(fid);
// redis为空则查询后再存
if(null==listResult) {
listResult=dictService.getDictByFid(fid);
RedisUtils.save(key, listResult);
}
//取得get/set方法,输入值
Method gm =null;Method sm =null;String allin=null;
if(!flag) {
gm =c.getMethod("get"+key, null);
sm =c.getMethod("set"+key, String.class);
}
//循环处理list
for(int i =0;i Object o = list .get(i);
if(flag) { allin=(String) ((Map) o).get(key);}
else { allin=(String) gm.invoke(o, null);}
System.out.println("输入量="+allin);
String out="";
//切割循环处理具体量
if (null!=allin&&!"".equals(allin)) {
String[] ins=allin.split(",");
for(int j =0;j String in =ins[j];
if (!"".equals(in)) {
String res=null;
//进行配对
for(int z =0;z if(ins[j].equals(((Map)listResult.get(z)).get("id"))) {
res=(String) ((Map)listResult.get(z)).get("name");break;
}
}
//未找到不处理
if (null==res) {
out=in;
}else {
out = out+res+" ";
}}
}
System.out.println("输出量="+out);
if(!flag) {sm.invoke(o, out);}
else{((Map) o).put(key, out);}
list.remove(i);
list.add(i, o);
}
}

}

} catch (Exception e) {
e.printStackTrace();
}
return list;

}

你可能感兴趣的:(项目中后台查询字典切换显示内容)