合并后的List如何再放入一个Map中?

heyingss 2009-02-20 04:35:38

List Inlst=originManage.find("select code,chdescirbe from Origin where code like '37%' and code=substr(code,1,4)||'00' order by tabIndex desc");

List Outlst=originManage.find("select code,chdescirbe from Origin where code not like '37%' and code=substr(code,1,2)||'0000' order by tabIndex desc");

并入一个List中
List Originlst=new ArrayList();
Originlst.add(Inlst);
Originlst.add(Outlst);

希望把合并后的List再放入一个Map,然后页面中遍历用。
...全文
346 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xlzhang66 2009-02-23
  • 打赏
  • 举报
回复
等待...
heyingss 2009-02-23
  • 打赏
  • 举报
回复
List Inlst=originManage.find("from DictOrigin where code like '37%' and code=substr(code,1,4)||'00' order by tabIndex desc");

List Outlst=originManage.find("from DictOrigin where code not like '37%' and code=substr(code,1,2)||'0000' order by tabIndex desc");

//放入map1
Map m1 = new HashMap();
Iterator t=Inlst.iterator();
while(t.hasNext()){
DictOrigin origin = (DictOrigin) t.next();
m1.put(origin.getCode(),origin.getDescribe());
}

//放入map2
Map m2 = new HashMap();
Iterator t2=Outlst.iterator();
while(t2.hasNext()){
DictOrigin origin = (DictOrigin) t2.next();
m2.put(origin.getCode(),origin.getDescribe());
}

//合并两个Map
m2.putAll(m1);

我只做到这样实现,先合并List再放入Map,不知道如何实现?请教各位?
heyingss 2009-02-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 pengling1985 的回复:]
引用 1 楼 mousetsun 的回复:
直接用list遍历就可以了啊~

正解,
生成一个map对象
遍历Originlst的时候,往map中加数据
[/Quote]
如何实现?
yukang_ky 2009-02-20
  • 打赏
  • 举报
回复
List Inlst=originManage.find("select code,chdescirbe from Origin where code like '37%' and code=substr(code,1,4)||'00' order by tabIndex desc");

List Outlst=originManage.find("select code,chdescirbe from Origin where code not like '37%' and code=substr(code,1,2)||'0000' order by tabIndex desc");

每个list里面存放其实不是Origin实体,而是Obejct[],你只有将Object[]转换为实体才行,如hql语句
select new Origin(o.code,o.chdescirbe from Origin as o where code like '37%' and code=substr(code,1,4)||'00' order by tabIndex desc)
并且在实体类中存在Origin(code,chdescirbe)的构造函数,才能转换为相应的实体。
yangqihong 2009-02-20
  • 打赏
  • 举报
回复
抛出异常:
java.lang.ClassCastException: java.util.ArrayList incompatible with com.sdbys.service.dict.origin.DictOrigin


类型转换异常,看看DictOrigin这个对象跟你的sql取出来的是否一致,也只有那2个元素。
Jacky_Zhu_1983 2009-02-20
  • 打赏
  • 举报
回复
Originlst 是有两个list对象啊...
两个list对象下面才是 DictOrigin
heyingss 2009-02-20
  • 打赏
  • 举报
回复
抛出异常:
java.lang.ClassCastException: java.util.ArrayList incompatible with com.sdbys.service.dict.origin.DictOrigin

遍历代码如下:
for(int i=0;i<Originlst.size();i++){
DictOrigin origin = (DictOrigin) Originlst.get(i);
origin.getCode();
origin.getDescribe();
}
pengling1985 2009-02-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mousetsun 的回复:]
直接用list遍历就可以了啊~
[/Quote]
正解,
生成一个map对象
遍历Originlst的时候,往map中加数据
Jacky_Zhu_1983 2009-02-20
  • 打赏
  • 举报
回复
直接用list遍历就可以了啊~

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧