对着电脑两个小时,代码一行没敲出来。是的,这是真的。然后,找到了别人教。。。。。。。渣渣林新手养成日记新番。关于Map,关于List。这里只写代码,不谢分析。因为,我根本分析不出来。如果各位看到了,千万不要怪我没有分析。谢谢各位浏览进来。
Map<String,List<RoleInfo>> operatorRoleMap = new HashMap<String,List<RoleInfo>>();
Map<String,Cooperator> operatorMap = new HashMap<String,Cooperator>();
List<Cooperator> list = new ArrayList<Cooperator>();
int count = 0;
if(cooGrid != null && (count = cooGrid.getRowCount()) > 0)
{
for(int i = 0;i < count; i++)
{
String adminId = cooGrid.getData(i,"AMINID");
if(!operatorRoleMap.containsKey(adminId))
{
Cooperator operator = new Cooperator();
operator.setAdminid(adminId);
operator.setUsername(cooGrid.getData(i,"USERNAME"));
operator.setOpenAccountTime(cooGrid.getData(i,"OPENACCOUNTTIME"));
operatorMap.put(adminId,operator);
List<RoleInfo> roleList = new ArrayList<RoleInfo>();
RoleInfo roleInfo = new RoleInfo();
roleInfo.setRoleName(cooGrid.getData(i,"ROLENAME"));
roleList.add(roleInfo);
operatorRoleMap.put(adminId,roleList);
}
else
{
List<RoleInfo> roleList = operatorRoleMap.get(adminId);
RoleInfo roleInfo = new RoleInfo();
roleInfo.setRoleName(cooGrid.getData(i,"ROLENAME"));
roleList.add(roleInfo);
}
}
}
for(Map.Entry<String,Cooperator>entry:operatorMap.entrySet())
{
Cooperator info = operatorMap.get(entry.getKey());
info.setRoleInfos(operatorRoleMap.get(entry.getKey()));
list.add(info);
}
List<Object> resList = new ArrayList<Object>();
resList.add(list);
resList.add(pageBean);
returnInfo.setResultList(resList);
public void setResultList(List<Object> resultList)
{
this.resultList = resultList;
}
public void setRoleInfos(List<RoleInfo> roleInfos)
{
this.roleInfos = roleInfos;
}
照着写了一遍,理解了一点点,然而,一点点。。。。。。。。。。。。