• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
星空摇曳
博客园    首页    新随笔    联系   管理    订阅  订阅
非空判断

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>

  

 

posted on 2019-08-07 14:34  星空摇曳  阅读(569)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3