用于测试查询列表输出,用于测试列表输出,用于测试查询列表输出pa
分享于 点击 2083 次 点评:60
用于测试查询列表输出,用于测试列表输出,用于测试查询列表输出pa
用于测试查询列表输出
package ims.common.util;import java.util.*;import org.apache.commons.beanutils.*;import java.io.*;/** * <p>Title: </p> * * <p>Description: </p> * 用于测试查询列表输出。 * <p>Copyright: Copyright (c) 2005</p> * * <p>Company: </p> * @author lin rui quan * @version 1.0 */public class DynaListToHTML { public DynaListToHTML() { } public static StringBuffer buildOutput(List list){ StringBuffer buf = new StringBuffer(); DynaBean bean; //显示数量 buf.append("<table id='count'>"); buf.append("<tr>"); buf.append("<td>"); buf.append("count:" + list.size()); buf.append("</td>"); buf.append("</tr>"); buf.append("</table>"); if(list.size()==0) return buf; buf.append("<table id='tabList' border=1> \r\n"); //设置标题 bean = (DynaBean)list.get(0); DynaProperty[] dps = bean.getDynaClass().getDynaProperties(); buf.append("<tr> \r\n"); for(int i=0; i<dps.length; i++){ buf.append("<td> \r\n"); buf.append(dps[i].getName()); buf.append("</td> \r\n"); } buf.append("</tr> \r\n"); //设置数据 for(int i=0; i<list.size(); i++){ buf.append("<tr> \r\n"); bean = (DynaBean)list.get(i); for(int j=0; j<dps.length; j++){ buf.append("<td> \r\n"); buf.append(bean.get(dps[j].getName())); buf.append("</td> \r\n"); } buf.append("</tr> \r\n"); } buf.append("</table>"); return buf; } public static StringBuffer buildOutput(List list,String sql,HashMap paramMap){ StringBuffer buf=new StringBuffer(); buf.append("<p>SQL语句:</p>"); buf.append("<textarea style='width:800px;height:400px'>"); buf.append(sql); buf.append("</textarea>"); buf.append("<p>参数:</p>"); buf.append("<textarea style='width:400px;height:400px'>"); buf.append(printHashMap(paramMap)); buf.append("</textarea>"); buf.append(buildOutput(list)); return buf; } public static void WriteHTMLFile(String fileName, StringBuffer buf){ File file = new File(fileName); try{ FileWriter out = new FileWriter(file); out.write(buf.toString()); out.close(); }catch(Exception e){ e.printStackTrace(); } } public static void toHTML(List list, String fileName){ StringBuffer buf = buildOutput(list); WriteHTMLFile(fileName, buf); } public static void toHTML(List list,String sql,HashMap paramMap,String fileName){ StringBuffer buf = buildOutput(list,sql,paramMap); WriteHTMLFile(fileName, buf); }// 打印HashMap的内容 public static String printHashMap(HashMap map) { StringBuffer buf=new StringBuffer(); if (map != null) { Object[] objs = map.keySet().toArray(); buf.append("------------------begin map--------------\n"); for (int i = 0; i < objs.length; i++) { if (map.get(objs[i]) != null) buf.append(" key {" + objs[i].toString() + "}is :(" + map.get(objs[i]).toString() + ") " + "value type is:" + map.get(objs[i]).getClass().getName()+"\n"); else { buf.append("the key "+objs[i]+" is null \n"); buf.append(map.get(objs[i])+"\n"); } } buf.append("------------------end map--------------\n"); } return buf.toString(); }}
用户点评