zoukankan      html  css  js  c++  java
  • 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)”

  • 相关阅读:
    MVC-READ5(asp.net web from PK asp.net MVC)
    MVC-READ4
    MVC-READ2
    MVC-READ1
    @@ERROR和@@ROWCOUNT的用法
    JS 对输入框文本正在输入中校验
    CSS 父级方法清除浮动方法
    jquery制作滚动条到一定位置触发
    嵌入式app框架
    开发常用软件
  • 原文地址:https://www.cnblogs.com/lixingwu/p/7113591.html
Copyright © 2011-2022 走看看