根据类名与列表返回table

.qtipTable {
	margin: 0;
	padding: 0;
	font-size: 12px;
}
.qtipBody {
	border-right: 1px solid #b5daff;
	border-top: 1px solid #b5daff;
    font-family: 微软雅黑,宋体,tahoma, Arial, Verdana, sans-serif;
    font-size: 12px;
}
.qtipBody th {
	border-left: 1px solid #b5daff;
	border-bottom: 1px solid #b5daff;
	vertical-align: middle;
	background-color: #d0e8ff;
	text-align:center;
	width:100px;
}
.qtipBody td {
	border-left: 1px solid #b5daff;
	border-bottom: 1px solid #b5daff;
	color: black;
}
.money_right{
	text-align:right;
	padding-right:2px;
}

	/**
	 * 根据list 返回table
	 * @param titlenm 标题名称
	 * @param pType Class
	 * @param pList 结果集
	 * @param pFieldNames 列名
	 * 例如:makeHTMLTable("rsvmain.title.rsvoccudtl", Rsvoccudtl.class, rsvoccudtlList, "blockId","rmcnt")
	 * @return
	 */
	public <T> String makeHTMLTable(String titlenm, Class<T> pType, List<T> pList, String... pFieldNames)
			throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException,
			NoSuchMethodException {
		String wFuncnm, wResult = "<div style='margin-bottom: 5px;'><span style='font-size:14px;font-weight:bold;'>"
				+ ApplicationContextUtil.getMessage(titlenm)
				+ "</span></div><div class='qtipTable'><table class='qtipBody' cellspacing='0' border=0 width='100%'><tr>";
		//获得Class
		String wClassnm = pType.getName().substring(pType.getName().lastIndexOf(".") + 1);
		//遍历标题
		for (String fnm : pFieldNames) {
			wResult += "<th>" + ApplicationContextUtil.getMessage(wClassnm + "." + fnm) + "</th>";
		}
		wResult += "</tr>";
		Iterator<T> iterator = pList.iterator();
		while (iterator.hasNext()) {
			wResult += "<tr>";
			T t = (T) iterator.next();
			for (String fnm : pFieldNames) {
				wFuncnm = "get" + fnm.substring(0, 1).toUpperCase() + fnm.substring(1);
				String tmpString = pType.getMethod(wFuncnm).invoke(t).toString();
				//判断如果是数字,则右对齐
				if (tmpString.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$")) {
					wResult += "<td class='money_right'>" + tmpString + "</td>";
				} else {
					wResult += "<td>" + tmpString + "</td>";
				}
			}
			wResult += "</tr>";
		}
		wResult += "</table></div>";
		return wResult;
	}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值