非空判断

String字符串

String id= null == request.getParameter("id") ? "" : request.getParameter("id").toString();

if(null != id && !id.equals("")){
    //不为空
}

import org.apache.commons.lang3.StringUtils;
if(StringUtils.isNotEmpty(id)){
    //不为空
}

Integer

null != Integer ;

对象

null != object

List集合

if(null != list && list.size()>0 ){
 
}

list.isEmpty()和list.size()==0 没有区别

Map集合

if (null != map && map.size() > 0) {
//不为空
}

JavaScript

var actiName = $('#activity_name').val();
//$.trim()函数会移除字符串开始和末尾处的所有换行符,空格(包括连续的空格)和制表符。如果这些空白字符在字符串中间时,它们将被保留,不会被移除。
if(null == actiName  || '' == $.trim(actiName )){
    alert('请输入活动名称!');
    return false;
}

//判断相等时
if(activity_type == '1'){

}

 jsp

第一种情况:页面之间传参,判断参数是否为空

<a href="../info/to.jsp?area_id=<%=area_id%>&customercode=<%=customercode%>">xxx</a>

<c:if test="${empty param.customercode }">
  <%-- 为空 --%>
</c:if>

<c:if test="${not empty param.customercode }">
  <%-- 不为空 --%>
</c:if>

第二种情况:后台传值到页面,判断参数是否为空

request.setAttribute("customercode", customercode);
request.setAttribute("orderList", orderList);

<c:choose>
	<c:when test="${empty customercode}">
		<!-- customercode为空 -->
	</c:when>
	<c:when test="${empty orderList}">
		<!-- orderList为空 -->
	</c:when>
	<c:otherwise></c:otherwise>
</c:choose>

  

 

转载于:https://www.cnblogs.com/zybcn/p/11315097.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值