大家帮帮忙看看,这里贴出来的是部分代码:
ModuleconfigUtil mcd=new ModuleconfigUtil ();
List cxun=mcd.getQiChaoInfo(commenFlowModuleId); // cxun.size()返回长度是5
QicaoAndQueryModuleBean[] ddddd=new QicaoAndQueryModuleBean[cxun.size()];
for(int i=0;i<chuxun.size();i++){
ddddd[i]=(QicaoAndQueryModuleBean)chuxun.get(i);
System.out.println("sddid="+ddddd[i].getModuleId()+"\n"+"sddname="+ddddd[i].getModuleName()+"\n"+"sddurl="+ddddd[i].getModuleUrl());
}
为什么后台只是重复的打印五次第一个QicaoAndQueryModuleBean的信息?
我要的效果是后台打印五个存储在List里面的QicaoAndQueryModuleBean的每一个的信息。
谁知道我哪里写错了?
ModuleconfigUtil mcd=new ModuleconfigUtil ();
List cxun=mcd.getQiChaoInfo(commenFlowModuleId); // cxun.size()返回长度是5
QicaoAndQueryModuleBean[] ddddd=new QicaoAndQueryModuleBean[cxun.size()];
for(int i=0;i<chuxun.size();i++){
ddddd[i]=(QicaoAndQueryModuleBean)chuxun.get(i);
System.out.println("sddid="+ddddd[i].getModuleId()+"\n"+"sddname="+ddddd[i].getModuleName()+"\n"+"sddurl="+ddddd[i].getModuleUrl());
}
为什么后台只是重复的打印五次第一个QicaoAndQueryModuleBean的信息?
我要的效果是后台打印五个存储在List里面的QicaoAndQueryModuleBean的每一个的信息。
谁知道我哪里写错了?
ModuleconfigUtil mcd=new ModuleconfigUtil();
List cxun=mcd.getQiChaoInfo(commenFlowModuleId); // cxun.size()返回长度是5
QicaoAndQueryModuleBean[] ddddd=new QicaoAndQueryModuleBean[cxun.size()];
for(int i=0;i <cxun.size();i++){
ddddd[i]=(QicaoAndQueryModuleBean)cxun.get(i);
System.out.println("sddid="+ddddd[i].getModuleId()+"\n"+"sddname="+ddddd[i].getModuleName()+"\n"+"sddurl="+ddddd[i].getModuleUrl());
}
cxun 写错了?
--------------------
我不知道怎么能用代码模版贴出来,另:次测试测程序放在eclipse下面的测试类里面的效果是后台打印五个存储在List里面的QicaoAndQueryModuleBean的每一个的信息,正确,现在把他放在jsp里面就是反复打印五次第一个bean信息了,疑问:eclipse跟jsp有仇???
List cxun=mcd.getQiChaoInfo(commenFlowModuleId); 返回的是五个一样的Bean.未完待续.....
List ls=new ArrayList();
//查询出来的语句查出五个bean的信息。
String queryQiChaoPageUrl="select * from module where parentid in="+ChildModuleId+" and pageurl like '/start%'";
try{
conn=db.getConnection();
st=conn.createStatement();
rs=st.executeQuery(queryQiChaoPageUrl);
while(rs.next()){
//qicao 是在类方法声明变量时new了的。就new了一个。
qicao.setModuleUrl(rs.getString("pageurl"));
qicao.setModuleId(rs.getString("moduleid"));
qicao.setModuleName(rs.getString("modulename"));
qicao.setModuleParentId(String.valueOf(rs.getString("parentid")));
ls.add(qicao);
}
//省略相关catch,finally处理代码
} return ls;
}
public List getQiChaoInfo(String ChildModuleId)
List ls=new ArrayList();
String queryQiChaoPageUrl="select * from module where parentid in="+ChildModuleId+" and pageurl like '/start%'";
try{
conn=db.getConnection();
st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery(queryQiChaoPageUrl);
rs.last(); //移到最后一行
int rowCount = rs.getRow(); //得到当前行号,也就是记录数
rs.beforeFirst();
int i=0;
QicaoAndQueryModuleBean[] qicao=new QicaoAndQueryModuleBean[rowCount];
while(rs.next()){
i++;
qicao[i].setModuleUrl(rs.getString("pageurl"));
qicao[i].setModuleId(rs.getString("moduleid"));
qicao[i].setModuleName(rs.getString("modulename"));
qicao[i].setModuleParentId(String.valueOf(rs.getString("parentid")));
ls.add(qicao[i]);
//省略相关catch,finally处理代码
} return ls;
}
List ls=new ArrayList();
//查询出来的语句查出五个bean的信息。
String queryQiChaoPageUrl="select * from module where parentid in="+ChildModuleId+" and pageurl like '/start%'";
try{
conn=db.getConnection();
st=conn.createStatement();
rs=st.executeQuery(queryQiChaoPageUrl);
while(rs.next()){
//在这里要写NEW代码
qicao = new ?();
qicao.setModuleUrl(rs.getString("pageurl"));
qicao.setModuleId(rs.getString("moduleid"));
qicao.setModuleName(rs.getString("modulename"));
qicao.setModuleParentId(String.valueOf(rs.getString("parentid")));
ls.add(qicao);
}
//省略相关catch,finally处理代码
} return ls;
}
为什么呢?
因为循环往list里面放QicaoAndQueryModuleBean的时候,每次要new一个,否则就出现这种情况了 就错在这//qicao 是在类方法声明变量时new了的。就new了一个。
我把程序改过来了,运行成功,谢谢大家!!
吃饭去
List ls=new ArrayList();
String queryQiChaoPageUrl="select * from module where parentid in="+ChildModuleId+" and pageurl like '/start%'";
try{
conn=db.getConnection();
st=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery(queryQiChaoPageUrl);
rs.last(); //移到最后一行
int rowCount = rs.getRow(); //得到当前行号,也就是记录数
rs.beforeFirst(); //这里改为rs.first()试试
int i=0;
QicaoAndQueryModuleBean[] qicao=new QicaoAndQueryModuleBean[rowCount]; //这里应该分配rowCount个容量对吧?
while(rs.next()){
i++; //你的i++是不是应该放到后面去,否则你的qicao[0]的数据是不是就没了?
qicao[i].setModuleUrl(rs.getString("pageurl"));
qicao[i].setModuleId(rs.getString("moduleid"));
qicao[i].setModuleName(rs.getString("modulename"));
qicao[i].setModuleParentId(String.valueOf(rs.getString("parentid")));
ls.add(qicao[i]);
//省略相关catch,finally处理代码
} return ls;
}