springmvc中的jsp页面<c:if>的使用

首先看一个实实在在的项目文档

<%@ 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这个变量名称不为空的话,就显示出来,如果为空的话,就不显示。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值