两个表:
lb(类别)和lbmx(类别明细),两个表之间没有特别指明关系,但是两个表都有一个字段: type
问题:
写一个方法当别人传这个type时查得lbmx中的记录(lbmx其中有两个字段:key,value)返回一个list,然后把list中的记录分别放到hashMap中,返回去.我写的:但是不知道怎么放到hashMap中: public List getDirList(String type){
List list = null;
List arrys=new ArrayList();
Map map=new HashMap();
try {
list=super.list("from TblGeneralDir where gtype="+type);
for(int i=0;i<list.size();i++)
{
map.put("","");
}
arrys.add(map);
} catch (Exception e) {
e.printStackTrace();
}
return arrys;
}
lb(类别)和lbmx(类别明细),两个表之间没有特别指明关系,但是两个表都有一个字段: type
问题:
写一个方法当别人传这个type时查得lbmx中的记录(lbmx其中有两个字段:key,value)返回一个list,然后把list中的记录分别放到hashMap中,返回去.我写的:但是不知道怎么放到hashMap中: public List getDirList(String type){
List list = null;
List arrys=new ArrayList();
Map map=new HashMap();
try {
list=super.list("from TblGeneralDir where gtype="+type);
for(int i=0;i<list.size();i++)
{
map.put("","");
}
arrys.add(map);
} catch (Exception e) {
e.printStackTrace();
}
return arrys;
}
list=super.list("from TblGeneralDir where gtype="+type);
返回TblGeneralDir类型。TblGeneralDir类的对象xxx相应的属性应该有getter方法吧。
放入Map:map.put(xxx.getKey(),xxx.getValue());
List arrys=new ArrayList();
Map map=new HashMap();
try {
TblGeneralDir dir=(TblGeneralDir)super.list("from TblGeneralDir where gtype="+type);
for(int i=0;i<list.size();i++)
{
map.put(dir.getGkey(),dir.getGvalue());
}
arrys.add(map);
} catch (Exception e) {
e.printStackTrace();
}
return arrys;
} 是这样的吗?查的记录时返回实例.
{
TblGeneralDir dir=(TblGeneralDir)list;
map.put(dir.getGkey(),dir.getGvalue());
}
我这样写了报了一错!不能把list强制转换成TblGeneralDir ,那我怎么把他们里面的键值和键名放到hashmap中啊?急!!!!!!!!!!!!
*************lz在下面循环的list集合从哪里来???******************
public List getDirList(String type){
List arrys=new ArrayList();
Map map=new HashMap();
try {
TblGeneralDir dir=(TblGeneralDir)super.list("from TblGeneralDir where gtype="+type); //lz循环的list集合从哪里来???
for(int i=0;i<list.size();i++)
{
map.put(dir.getGkey(),dir.getGvalue());
}
arrys.add(map);
} catch (Exception e) {
e.printStackTrace();
}
return arrys;
} 是这样的吗?查的记录时返回实例.
{
TblGeneralDir dir=(TblGeneralDir)list.get(i);//list.get(i)
map.put(dir.getGkey(),dir.getGvalue());
}