java 判断对象的所有属性是否为空解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/saygood999/article/details/78782550
public static boolean allfieldIsNUll(Object o){
    try{
        for(Field field:o.getClass().getDeclaredFields()){
            field.setAccessible(true);//把私有属性公有化
            Object object = field.get(o);
            if(object instanceof CharSequence){
                if(!ObjectUtils.isEmpty((String)object)){
                    return false;
                }
            }else{
                if(!ObjectUtils.isNUll(object)){
                    return false;
                }
            }

        }
    }catch (Exception e){
        e.printStackTrace();
    }
    return true;
}
如果帮到你了,求打赏
 
 
 
  
 

猜你喜欢

转载自blog.csdn.net/saygood999/article/details/78782550