JSTL 和 入門級~

1、<C:If>標籤:條件判斷語句html

 

<c:if test="${objList.nodetype == 1}">上級節點</c:if>  

 

 

test爲if語句的判斷條件。執行與java中的一致。java

 

 

簡單總結幾種判空的處理:node

一、集合判空。利用關鍵字  emptyspa

<c:if test="${ empty list}">   
  
//要執行的語句...  
  
</c:if>  

 


二、集合判空的另外一種方式.net

 


 
<c:if test="${mdxDimensionInfoList=='[]'}">  
  
//要執行的代碼...  
  
</c:if>  

 

三、字符串判空code

 

 

<c:if test="${query01 == null}">  
  
  //執行代碼...  
  
</c:if>  
  
或者  
  
<c:if test="${query01 == ''}">  
  
  //執行代碼...  
  
</c:if>  

 



四、判斷兩個字串是否相等orm

 


 


2、<C:ForEach>標籤,循環取值htm

       <C:ForEach> 通常使用的兩個重要屬性,blog

        items------要循環遍歷的集合ip

        var----------迭代器名稱,通俗點說就是用var來 取值,(見下)

        C:out-------經過C:Out將值顯示在頁面

 
 
<c:forEach items="${mdxMeasureInfoList}" var="obj">  
    <tr>  
           <td width="20%"><c:out value="${obj.measureName}"></c:out></td>  
           <td width="20%"><c:out value="${obj.myFildName}"></c:out></td>  
           <td width="20%"><c:out value="${obj.unit}"></c:out></td>  
           <td width="20%"><c:out value="${obj.calFormula}"></c:out></td>  
    </tr>  
</c:forEach>  

 

 

例子: C:if + C:forEach

 

//<c:forEach><c:if>分開使用  
  
<table>  
    <tbody>  
        <c:forEach items="${mdxMeasureInfoList}" var="obj">  
            <tr>  
                <td width="20%"><c:out value="${obj.measureName}"></c:out></td>  
                <td width="20%"><c:out value="${obj.myFildName}"></c:out></td>  
                <td width="20%"><c:out value="${obj.unit}"></c:out></td>  
                <td width="20%"><c:out value="${obj.calFormula}"></c:out></td>  
            </tr>  
        </c:forEach>  
  
        <c:if test="${mdxMeasureInfoList=='[]'}">  
            <tr>  
                <td colspan="11"><font color="red">很抱歉 沒有能夠展現的數據!</font></td>  
            </tr>  
        </c:if>  
    </tbody>  
</table>  
  
  
  
  
//例子2:<c:forEach><c:if>嵌套使用  
  
<table>  
    <tbody>  
  
                //page.content,是由於在controller中將傳過來的list封裝在了pagebean實體中,  
                //因此取值時爲page.content。普通集合取值時,不用加 .content  
  
        <c:forEach items="${page.content}" var="obj">  
            <tr>  
                <td width="30px"><input name="id" type="checkbox" value="${obj.id}" /></td>  
                <td width="15%"><c:out value="${obj.measureName}"></c:out></td>  
                <td width="15%"><c:out value="${obj.myFildName}"></c:out></td>  
                <td width="15%"><c:out value="${obj.unit}"></c:out></td>  
                <td width="15%">  
                <c:if test="${obj.measureAggregator=='sum'}">總和</c:if>  
                <c:if test="${obj.measureAggregator=='count'}">計數</c:if>  
                <c:if test="${obj.measureAggregator=='min'}">最小值</c:if>  
                <c:if test="${obj.measureAggregator=='max'}">最大值</c:if>  
                <c:if test="${obj.measureAggregator=='avg'}">平均值</c:if>  
                </td>  
                <td width="15%">  
                <c:if test="${obj.ifDisplay=='0'}">顯示</c:if>  
                <c:if test="${obj.ifDisplay!='0'}">隱藏</c:if>  
                </td>  
            </tr>  
        </c:forEach>  
    </tbody>  
</table> 
相關文章
相關標籤/搜索