jsp 动态显示列

1    controller.java


        List<String> ths = new ArrayList<String>();   // ths = [鼠疫, 霍乱]--列名


        List<String> tds = new ArrayList<String>();  // tds = [101, 102]--列名对应的代码


        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

// list = [{ORGAN_CODE=8651, 101=0, 102=0}, 

{ORGAN_CODE=8652, 101=1, 102=3},

{ORGAN_CODE=8653, 101=0, 102=0},

{ORGAN_CODE=8665, 101=0, 102=0},

{ORGAN_CODE=8606, 101=0, 102=0},

{ORGAN_CODE=8667, 101=0, 102=0},

{ORGAN_CODE=8668, 101=0, 102=2},

{ORGAN_CODE=8630, 101=0, 102=0}]

列对应的值,以列code为key


2   a.jsp


   <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <%--   计算共${(fn:length(ths)) +1}--%>        

    <table>
        <colgroup>

             <col style="width: 30px;min-width:30px;" /><%--   机构列:列比较宽,单独处理 --%>      

            <c:forEach var="th" items="${ths}" varStatus="status"> <%--   循环列宽 --%>         
                <col style="width: 10px;min-width:10px;" />
            </c:forEach>

        </colgroup>
        <thead>
            <tr>
                <th colspan="${(fn:length(ths)) +1}">****报表 </th><%--   合并标题行:机构单列+动态列 =${(fn:length(ths)) +1}--%>

            </tr>
            <tr>
                <th >上报机构</th> <%--   机构列单独处理列名(固定列) --%>        
                <c:forEach var="th" items="${ths}" varStatus="status"> <%--   循环动态列名 --%>        
                    <th>${th}</th>
                </c:forEach>

            </tr>
        </thead>
    </table>
    
    <table>
        <colgroup>
               <col style="width: 30px;min-width:30px;" /><%--   机构列:列比较宽,单独处理 --%>   
              <c:forEach var="th" items="${ths}" varStatus="status">
                <col style="width: 10px;min-width:10px;" /><%--   循环列宽 --%>
            </c:forEach>

        </colgroup>
        <tbody>
            <c:forEach var="result" items="${results}" varStatus="status">
                <tr>
                     <%--   机构列数据显示--%>   
                     <td><ehr:org code="${result.ORGAN_CODE}"/></td>
                    <%--   动态列数据显示 --%>   
                    <c:forEach var="td" items="${tds}" varStatus="status">
                        <td>${result[td]}</td> <%--   例子:result.鼠疫 类似 result.ORGAN_CODE,但格式为result[td]--%>
                    </c:forEach>
                </tr>
            </c:forEach>

        </tbody>
    </table>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值