判断map中是否有该key,并且获取的对象不是null且不是空

public static Boolean hasObjectByMap(Map<String, Object> params, String key)
    {
        // 如果key为空,或者params为空,则直接返回false
        if (isEmptyString(key) || params == null || params.isEmpty())
        {
            return false;
        }
        // params中不包含key,返回false
        if (!params.containsKey(key))
        {
            return false;
        }
        Object obj = params.get(key);
        // 如果obj为空,则返回空
        if (obj == null)
        {
            return false;
        }
        // 如果obj属于字符串类型的,则按照字符串的来判断
        if (obj instanceof String)
        {
            return !isEmptyString((String) obj);
        }

        return true;
    }
public static boolean isEmptyString(String strValue)
    {
        boolean bIsEmpty = false;
         
        if (null == strValue || strValue.trim().equals("") || strValue.trim().equalsIgnoreCase("null"))
        {
            bIsEmpty = true;
        }
         
        return bIsEmpty;
    }

  

  

原文地址:https://www.cnblogs.com/pt-lqb/p/14030888.html