67,538
社区成员
发帖
与我相关
我的任务
分享
//循环嵌套有问题想想当s=6的时候p=0,1,2,...fatherlist.size();
//下面的equals判断有意义吗?新建测试组equals测试组
//当然执行esle然后把测试组加了进入了(fatherlist.add(fathermap);)
//还有就是你构造数据出了问题 多用用debug吧 清晰明了
for(int s=0;s <k;s++)
for(int p=0; p <fatherlist.size();p++)
{
//逻辑有问题
if(((fathermap.get("zuname")).toString()).trim().equals((((fatherlist.get(p).get("zuname")).toString()).trim()))==true)
{
// System.out.println("取到map里的的zuname是"+(fathermap.get("zuname")).toString());
// System.out.println("取到list里的的zuname是"+(fatherlist.get(p).get("zuname")).toString());
break;
}else
{
//System.out.println("比对后相等添加记录");
//map 5,6,7,8,9都符合判断 输出了这个咯{fathernodeid=0, zuname=测试组, zuid=4}
fatherlist.add(fathermap);
}
-- Create table
create table THINK_TEST
(
ID VARCHAR2(50),
NAME VARCHAR2(20),
EMAILADDRESS VARCHAR2(50),
LASTLOGON VARCHAR2(50)
)
-- insert data
insert into think_test values('100','test4','test4@yahoo.cn','2007-11-25 16:31:26 ');
insert into think_test values('13','test1','test1@yahoo.cn','2007-3-22 16:27:07');
insert into think_test values('19','test1','test1@yahoo.cn','2007-10-25 14:13:46');
insert into think_test values('42','test1','test1@yahoo.cn','2007-11-20 14:20:10');
insert into think_test values('45','test2','test2@yahoo.cn','2007-4-25 14:17:39');
insert into think_test values('49','test2','test2@yahoo.cn','2007-5-25 14:22:36 ');
--preview date
select * from think_test;
ID NAME EMAILADDRESS LASTLOGON
-------------------------------------------------- -------------------- -------------------------------------------------- --------------------------------------------------
100 test4 test4@yahoo.cn 2007-11-25 16:31:26
13 test1 test1@yahoo.cn 2007-3-22 16:27:07
19 test1 test1@yahoo.cn 2007-10-25 14:13:46
42 test1 test1@yahoo.cn 2007-11-20 14:20:10
45 test2 test2@yahoo.cn 2007-4-25 14:17:39
49 test2 test2@yahoo.cn 2007-5-25 14:22:36
--execute sql
select *
from(
select t.*,RANK() OVER (PARTITION BY t.name order by rownum desc) Rnk
from think_test t
) tt
where tt.rnk<2;
ID NAME EMAILADDRESS LASTLOGON RNK
-------------------------------------------------- -------------------- -------------------------------------------------- -------------------------------------------------- ----------
42 test1 test1@yahoo.cn 2007-11-20 14:20:10 1
49 test2 test2@yahoo.cn 2007-5-25 14:22:36 1
100
drop table think_test;
public List getgroupNameById(String gid) {
int newgid=Integer.parseInt(gid);
String sql ="select a.id as zuid, a.company_id as cid, a.group_name as zuname, a.state as stat from hrp_custom_group as a where `company_id`="+newgid;
List list =jdbctemplate.queryForList(sql);
return list;
} 这是数据层的方法 获得所有组的名称
public List getAllById(String gid) {
// TODO Auto-generated method stub
int ngid = Integer.parseInt(gid);
String sql ="select a.id as zuid,a.group_name as zuname,b.employee_id as renyuanid,c.employee_name as renname from hrp_custom_group as a inner join hrp_custom_group_details as b on a.id = b.group_id inner join hrp_company_employee_info as c on b.employee_id = c.id where a.company_id="+ngid;
List gdlist = jdbctemplate.queryForList(sql);
if(gdlist.size()>0){
return gdlist;
}else{
return null;
}
}
这个是获得所有组里成员的方法 public String getall(){
String gid ="4";
allgds=gds.getAllById(gid);
int k =allgds.size();
groupnamelist = gds.getName(gid);
int w =groupnamelist.size();
List<Map> fatherlist = new ArrayList();
List<Map> childlist =new ArrayList();
for(int s=0;s<w;s++)
{
Map fathermap= new HashMap();
fathermap.clear();
fathermap.put("fathernodeid", 0);
fathermap.put("zuid", ((Map)groupnamelist.get(s)).get("zuid"));
fathermap.put("zuname", ((Map)groupnamelist.get(s)).get("zuname"));
fatherlist.add(fathermap);
}
for(int f=0;f<k;f++)
{
Map childmap= new HashMap();
childmap.put("renyuanid", ((Map)allgds.get(f)).get("renyuanid"));
childmap.put("zuid", ((Map)allgds.get(f)).get("zuid"));
childmap.put("renname", ((Map)allgds.get(f)).get("renname"));
childlist.add(childmap);
}
newfatherlist = fatherlist;
newchildlist = childlist;
if(allgds.size()>0){
return "getallok";
}else{
return "getallno";
}
}这是action里的代码