springmvc中的jsp頁面<c:if>的使用,springmvcjsp

來源:互聯網
上載者:User

springmvc中的jsp頁面<c:if>的使用,springmvcjsp

首先看一個實實在在的項目文檔

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>   <%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!doctype html><html lang="zh-cn"><head><base href="<%=basePath%>"><meta charset="UTF-8"><meta name="Keywords" content="種籌天下" /><meta name="Description" content="種籌天下" /><title>種籌天下</title><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=ture"><link rel="stylesheet" href="m/css/other.css"></head><body><!-- <div id="header">   <div class="header_left_btn">   <a href="javascript:window.history.go(-1);"><img src="m/images/back.png" height="28"></a>   </div>  <p class="header_tt">搜尋結果</p></div> --><div id="main">  <div class="search_box">  <c:if test="${! empty testUnit.crop_name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【作物名稱】</font></span><span class="search_right" style="width:65%">${testUnit.crop_name }</span></p></c:if>  <c:if test="${! empty testUnit.service_item}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【服務項目】</font></span><span class="search_right" style="width:65%">${testUnit.service_item } ${testUnit.service_item_son }</span></p></c:if>  <c:if test="${! empty testUnit.method}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【測試方法】</font></span><span class="search_right" style="width:65%">${testUnit.method }</span></p></c:if>  <c:if test="${! empty testUnit.wait_data}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【等待時間】</font></span><span class="search_right" style="width:65%">${testUnit.wait_data }</span></p></c:if>  <c:if test="${! empty testUnit.cost}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【費用】</font></span><span class="search_right" style="width:65%">${testUnit.cost }</span></p></c:if>    <c:if test="${! empty testUnit.name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【單位名稱】</font></span><span class="search_right" style="width:65%">${testUnit.name }</span></p></c:if>  <c:if test="${! empty testUnit.address}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【地址】</font></span><span class="search_right" style="width:65%">${testUnit.address }</span></p></c:if>  <c:if test="${! empty testUnit.contactor}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【連絡人】</font></span><span class="search_right" style="width:65%">${testUnit.contactor }</span></p></c:if>  <c:if test="${! empty testUnit.phone_number}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【電話】</font></span><span class="search_right" style="width:65%">${testUnit.phone_number }</span></p></c:if>  <c:if test="${! empty testUnit.introduction}"><p class="search_p clearfix"><span class="search_tt"><font color=green>【測試單位簡介】</font></span></p>  <p class="search_p clearfix"><span class="search_tt">${testUnit.introduction}</span></p></c:if>    <p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【國家】</font></span><span class="search_right" style="width:65%">${testUnit.country }</span></p>  <p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【地區】</font></span><span class="search_right" style="width:65%">${testUnit.area_province } ${testUnit.area_city } ${testUnit.area_county }</span></p>  <c:if test="${! empty testUnit.picture}"><p class="search_p clearfix"><span class="search_tt"><font color=green>【相關圖片】</font></span></p>  <table width="90%" border="0" cellspacing="0" cellpadding="0" style="margin:12px auto 50px;">  <c:set value="${fn:split(testUnit.picture,';')}" var="pictures"  />       <c:forEach items="${pictures }" var="pict" varStatus="s">       <tr>       <td ><img width="100%" height="65%" src="${pict }"></td>       </tr>       <tr>       <td> </td>       </tr>       </c:forEach>    </table>  </c:if>    </div>    </div></body></html>


總結一下其中的<c:if>的使用:

<c:if test="${! empty testUnit.crop_name}"><p class="search_p clearfix"><span class="search_left" style="width:30%"><font color=green>【作物名稱】</font></span><span class="search_right" style="width:65%">${testUnit.crop_name }</span></p></c:if>

意思是,如果testUnit.crop_name這個變數名稱不為空白的話,就顯示出來,如果為空白的話,就不顯示。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.