大家帮帮忙看看,这里贴出来的是部分代码:
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的每一个的信息。
谁知道我哪里写错了?

解决方案 »

  1.   

    写错了,是这个
    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()); 

      

  2.   

    chuxun   
    cxun 写错了? 
      

  3.   

    楼上的老兄,其实chuxun就是cxun了,改正过来也老是重复打印第一个Bean的值??
      

  4.   

    暂时未发现异常,请楼主监视一下cxun中的5个元素是否是相同的?另:以后帖代码请用代码模板帖出来,方便阅读
      

  5.   

    另:以后帖代码请用代码模板帖出来,方便阅读
    --------------------
    我不知道怎么能用代码模版贴出来,另:次测试测程序放在eclipse下面的测试类里面的效果是后台打印五个存储在List里面的QicaoAndQueryModuleBean的每一个的信息,正确,现在把他放在jsp里面就是反复打印五次第一个bean信息了,疑问:eclipse跟jsp有仇???
      

  6.   

    暂时怀疑
    List cxun=mcd.getQiChaoInfo(commenFlowModuleId);  返回的是五个一样的Bean.未完待续.....
      

  7.   

    public List getQiChaoInfo(String ChildModuleId) {
     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;  
           }
      

  8.   

    楼上的,不要急,正在查public List getQiChaoInfo(String ChildModuleId)这个方法
      

  9.   

    我把方法改了,但是后台报错:NULLpointEcxeption 
    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;   
           }
      

  10.   

    public List getQiChaoInfo(String ChildModuleId) { 
     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;   
           }
      

  11.   

    呵呵,我知道你的问题在哪!你那个List里面5个值就是重复的。
    为什么呢?
    因为循环往list里面放QicaoAndQueryModuleBean的时候,每次要new一个,否则就出现这种情况了 就错在这//qicao 是在类方法声明变量时new了的。就new了一个。 
      

  12.   

    实践证明:xuxiaosz 的方法是正确的,zang1也指出了问题的错误根源,
    我把程序改过来了,运行成功,谢谢大家!!
    吃饭去
      

  13.   

    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();  //这里改为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;    
           }