java 判断数据是否为空


  /**
     * 方法描述:自定义判断是否为空
     * 创建作者:李兴武
     * 创建日期:2017-06-22 19:50:01
     *
     * @param str the str
     * @return the boolean
     */
    public static Boolean isBlank(String str) {
        if (str != null)
            str = str.replaceAll("\r\n|\n\r|\n|\r|\f|\t", "");
        if (str == null)
            return true;
        else if (str.equals(""))
            return true;
        else if (str.equals("null"))
            return true;
        else if (str.equals("NULL"))
            return true;
        else if (str.equals("(null)"))
            return true;
        else if (str.equals("(NULL)"))
            return true;
        else if (str.trim().length() == 0)
            return true;
        return false;
    }

    /**
     * 方法描述:判断obj是否为空
     * 创建作者:李兴武
     * 创建日期:2017-06-22 19:50:01
     *
     * @param obj the 判断的对象
     * @return the boolean
     */
    public static Boolean isBlank(Object obj) {
        if (obj != null) {
            return isBlank(String.valueOf(obj));
        }
        return true;
    }

 

以下字符全部返回true

1. \r\n|\n\r|\n|\r|\f|\t
2. null
3. “”
4. “null”
5. “NULL”
6. “(null)”
7. “(NULL)”


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM