zoukankan      html  css  js  c++  java
  • JSTL c:forEach没有循环到值的判断

    事件背景:<table>检索到的数据列表,主表存在关系表的id或者code情况,如订单主表,存在会员id,为了显示更友好,需要根据id显示name。由于前期数据不完善或者存在数据删除情况,导致传统的关联查询如inner join查的数据不全。

    解决方式1: 

    select a.*,b.name as name from a inner join b where 1=1 and ...
    union
    select a.*,null as name from a where 1=1 and not exists (select * from b where a.name_id = b.id) and ...

    然后entity里赋值name,传入前台,直接显示name

    解决方式2:

    controller page方法里,增加关联表的list,传入前台

    <c:forEach items="${page.list}" var="var" varStatus="vs">
    <tr>
        <td>${var.orderId}</td>
        ...
        <c:forEach items="${shoplist}" var="shop">
            <c:if test="${var.shopId == shop.id }">
            <c:set var="count" scope="session" value="1"/>
            <td>${shop.name}</td>
        </c:if>
        </c:forEach>
        <c:if test="${count ne 1}">
            <td></td>
        </c:if>  
        <c:set var="count" scope="session" value="0"/>       
    </tr>
    </c:forEach>
             

    使用<c:set 临时赋值count,表示当前取到了值,然后后面重置count=0,防止count值带到下一条数据。

  • 相关阅读:
    LINQ Provider表达式树6
    asp.net Forms 验证No.3
    三种用户验证No.1 asp.net Forms
    LinQ表达式目录2
    将ASP.NET MVC 2.0 部署在IIS6和IIS7上
    LINQ Provider 表达式树 5
    asp.net Forms验证No.2
    LINQ表达式树4
    LINQ表达式树3
    绝对精华win8如何使用,玩转win8看完绝不后悔
  • 原文地址:https://www.cnblogs.com/x-jingxin/p/12186838.html
Copyright © 2011-2022 走看看