检测参数不为空

/**
  * 入参校验
  * @param params 入参集合
  * @param paramNames 必需存在且不为空的参数名
  * @return 发现错误,返回错误信息,否则返回null
  */
 public static String checkParams(Map params, String... paramNames) {
  if (paramNames == null || paramNames.length == 0) {
   return null;
  }
  if (params == null || params.isEmpty()) {
   return "缺少必要的入参";
  }
  Object temp;
  for (String paramName : paramNames) {
   if (StringUtils.isBlank(paramName)) {
    continue;
   }
   temp = params.get(paramName);
   if (temp == null || StringUtils.isBlank(temp.toString())) {
    return "缺少必要的入参:" + paramName;
   }
  }
  return null;
 }

时间: 2024-08-28 06:47:55

检测参数不为空的相关文章

jQuery 工具类函数-检测对象是否为空

在jQuery中,可以调用名为$.isEmptyObject的工具函数,检测一个对象的内容是否为空,如果为空,则该函数返回true,否则,返回false值,调用格式如下: $.isEmptyObject(obj); 其中,参数obj表示需要检测的对象名称. <body> <div id="divtest"> <div class="title"> <span class="fl">检测对象是否为空&

使用Jayrock开源组件创建参数可为空的接口

经过上一篇文章对Jayrock开源组件的分析,我发现了一个问题,就是在写接口的时候,可以设置某个参数为空,可以不需要进行参数的传递,具体写法如下: 图上的test参数就是可空类型,只需标识为int?类型即可.测试结果如下: 使用非常的简单,也验证了我上一篇文章的错误观点,在此说明一下.

检测对象是否是空对象(摘)

/*   * 检测对象是否是空对象(不包含任何可读属性). //如你上面的那个对象就是不含任何可读属性  * 方法只既检测对象本身的属性,不检测从原型继承的属性.   */ function isOwnEmpty(obj)  {      for(var name in obj)      {          if(obj.hasOwnProperty(name))          {              return false;          }      }      ret

jstl 判断字符串是否为空C标签 &lt;c:if&gt;判断参数是否为空

C标签 <c:if>判断参数是否为空 <c:if test="${empty str}" > str为空 </c:if> <c:if test="${not empty str}"> str不为空 </c:if> ********************************************* <c:forEach var="menu" items="${ser

js通用工具方法检测对象是否为空

/*   * 检测对象是否是空对象(不包含任何可读属性).   * 方法只既检测对象本身的属性,不检测从原型继承的属性.   */ function isOwnEmpty(obj)  {      for(var name in obj)      {          if(obj.hasOwnProperty(name))          {              return false;          }      }      return true;  };    /* 

PHP检测参数是否为整数

if($_POST['call']==""||!is_numeric($_POST['call'])||strpos($_POST['call'],".")!==false) { echo "参数为空或不为整数"; } else { echo “参数检查合格”: }

检测session是否为空

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package cn.toher.filter; import cn.toher.bean.User; import java.io.IO

很好用的request转换为实体方法还有判断实体所有参数不能为空的方法

/// <summary> /// 模型辅助处理类 /// 2016-04-18 /// </summary> public class ModelHelper { /// <summary> /// 将数据转化为模型 /// 2016-04-18 基础数据类型:Int32,decimal /// </summary> /// <typeparam name="T"></typeparam> /// <par

PHP 检测变量是否为空

PHP 中以下值得计算结果为 false: 关键字 boolean false 整型 integer 0 浮点型 double 0.0 字符串 string ""  字符串 string  "0"  数组 array  array()  对象  object  空对象 php<5  null  null  NULL  例如 字符串"0": <?php $number = "0"; if($number) { ech