此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【kunmingkunlun】截止到2008-07-01 18:18:12的历史汇总数据(不包括此帖):
发帖数:42                 发帖分:1040               
结贴数:10                 结贴分:230                
未结数:32                 未结分:810                
结贴率:23.81 %            结分率:22.12 %            
楼主该结一些帖子了

解决方案 »

  1.   

    我以前写的一段代码,注释很清楚,希望有帮助
        /**
    * 生成HTML的table

    * list : 实体类集合
    * columnsToShow : 需要显示那些列,大小写敏感,交换顺序后表格顺序也交换
    * columnNames : 表头名称,需要和 columnsToShow 长度对应。如果为null,则显示列名

    * /
    public String createTableByListAndColumnNames(List list,
    String[] columnsToShow, String[] columnNames) {
    String table = "<table cellpadding=\"1\" cellspacing=\"1\" bgColor=\"#CCCCCC\" width=\"100%\">\n"; // 如果得到的list不为空,且数量大于0
    if (list != null && list.size() > 0) {
    // 得到List中的bean类
    Class c = list.get(0).getClass(); // bean类中的所有方法,包括父类方法
    Method[] m = c.getMethods(); // 将columnsToShow转换为Vector,方便下面的操作
    Vector columnsToShowVector = new Vector();
    for (int i = 0; i < columnsToShow.length; i++) {
    // 首字母大写,并加上“get”,方便下面的比较
    String column = "get"
    + ("" + columnsToShow[i].charAt(0)).toUpperCase()
    + columnsToShow[i].substring(1);
    columnsToShowVector.add(column);
    } // bean中所有以get开头的方法,不包括getClass和get方法,且必须在columnsToShow参数中指定
    Vector allGets = new Vector(); for (int i = 0; i < m.length; i++) {
    String currentMethodName = m[i].getName();
    if (currentMethodName.startsWith("get")
    && !currentMethodName.equals("getClass")
    && !currentMethodName.equals("get")
    && columnsToShowVector.contains(currentMethodName)) {
    allGets.add(m[i]);
    }
    } // 设置表头名
    if (columnNames != null) {// 如果手动设置了表头名
    table += "\t<tr>\n";
    for (int i = 0; i < columnNames.length; i++) {
    table += "\t\t<td bgColor=\"#E7EFFF\">\n";
    table += "\t\t\t<a href=\"javascript:newOrder('" + (i + 1)
    + "')\">" + columnNames[i] + "</a>\n";
    table += "\t\t</td>\n";
    }
    table += "\t</tr>\n";
    } else {// 如果没有手动设置表头名,则用默认名(使用bean中的属性名)
    table += "\t<tr>\n";
    for (int i = 0; i < allGets.size(); i++) {
    Method currentMethod = (Method) allGets.get(i);
    table += "\t\t<td bgColor=\"#E7EFFF\">\n";
    table += "\t\t\t<a href=\"javascript:newOrder('" + (i + 1)
    + "')\">" + currentMethod.getName().substring(3)
    + "</a>\n";
    table += "\t\t</td>\n";
    }
    table += "\t</tr>\n";
    } try {
    // 从list中取数据放到表中
    for (int i = 0; i < list.size(); i++) {
    table += "\t<tr>\n";
    for (int j = 0; j < allGets.size(); j++) {
    Method currentMethod = (Method) allGets.get(j);
    table += "\t\t<td bgColor=\"#FFFFFF\">\n";
    table += "\t\t\t"
    + currentMethod.invoke(list.get(i), null)
    + "\n";
    table += "\t\t</td>\n";
    }
    table += "\t</tr>\n";
    }
    } catch (IllegalArgumentException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    e.printStackTrace();
    }
    }
    table += "</table>\n";
    return table;
    }
      

  2.   

    注释是刚加的,格式错了,重新发一次/**
    * 生成HTML的table

    * list : 实体类集合
    * columnsToShow : 需要显示那些列,大小写敏感,交换顺序后表格顺序也交换
    * columnNames : 表头名称,需要和 columnsToShow 长度对应。如果为null,则显示列名

    */
    public String createTableByListAndColumnNames(List list,
    String[] columnsToShow, String[] columnNames) {
    String table = "<table cellpadding=\"1\" cellspacing=\"1\" bgColor=\"#CCCCCC\" width=\"100%\">\n"; // 如果得到的list不为空,且数量大于0
    if (list != null && list.size() > 0) {
    // 得到List中的bean类
    Class c = list.get(0).getClass(); // bean类中的所有方法,包括父类方法
    Method[] m = c.getMethods(); // 将columnsToShow转换为Vector,方便下面的操作
    Vector columnsToShowVector = new Vector();
    for (int i = 0; i < columnsToShow.length; i++) {
    // 首字母大写,并加上“get”,方便下面的比较
    String column = "get"
    + ("" + columnsToShow[i].charAt(0)).toUpperCase()
    + columnsToShow[i].substring(1);
    columnsToShowVector.add(column);
    } // bean中所有以get开头的方法,不包括getClass和get方法,且必须在columnsToShow参数中指定
    Vector allGets = new Vector(); for (int i = 0; i < m.length; i++) {
    String currentMethodName = m[i].getName();
    if (currentMethodName.startsWith("get")
    && !currentMethodName.equals("getClass")
    && !currentMethodName.equals("get")
    && columnsToShowVector.contains(currentMethodName)) {
    allGets.add(m[i]);
    }
    } // 设置表头名
    if (columnNames != null) {// 如果手动设置了表头名
    table += "\t<tr>\n";
    for (int i = 0; i < columnNames.length; i++) {
    table += "\t\t<td bgColor=\"#E7EFFF\">\n";
    table += "\t\t\t<a href=\"javascript:newOrder('" + (i + 1)
    + "')\">" + columnNames[i] + "</a>\n";
    table += "\t\t</td>\n";
    }
    table += "\t</tr>\n";
    } else {// 如果没有手动设置表头名,则用默认名(使用bean中的属性名)
    table += "\t<tr>\n";
    for (int i = 0; i < allGets.size(); i++) {
    Method currentMethod = (Method) allGets.get(i);
    table += "\t\t<td bgColor=\"#E7EFFF\">\n";
    table += "\t\t\t<a href=\"javascript:newOrder('" + (i + 1)
    + "')\">" + currentMethod.getName().substring(3)
    + "</a>\n";
    table += "\t\t</td>\n";
    }
    table += "\t</tr>\n";
    } try {
    // 从list中取数据放到表中
    for (int i = 0; i < list.size(); i++) {
    table += "\t<tr>\n";
    for (int j = 0; j < allGets.size(); j++) {
    Method currentMethod = (Method) allGets.get(j);
    table += "\t\t<td bgColor=\"#FFFFFF\">\n";
    table += "\t\t\t"
    + currentMethod.invoke(list.get(i), null)
    + "\n";
    table += "\t\t</td>\n";
    }
    table += "\t</tr>\n";
    }
    } catch (IllegalArgumentException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    e.printStackTrace();
    }
    }
    table += "</table>\n";
    return table;
    }
      

  3.   

    简单的很啊,看看jstl和structs遍历集合的标签源代码不就得了嘛,都是开源的。