/**
* 验证实体对象是否为空
*
* @param bean
* @param attributeName
* 自定义验证的
*/
public static boolean isEmpty(Object bean, String... attributeName) {
List<String> list = Arrays.asList(attributeName);
PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(bean);
for (PropertyDescriptor origDescriptor : origDescriptors) {
String name = origDescriptor.getName();
if (list.contains(name)) {
if ("class".equals(name)) {
continue;
}
if (PropertyUtils.isReadable(bean, name)) {
try {
Object value = PropertyUtils.getSimpleProperty(bean, name);
if (value == null) {
continue;
} else {
return false;
}
} catch (java.lang.IllegalArgumentException ie) {
;
} catch (Exception e) {
;
}
}
} else {
continue;
}
}
return true;
}
/**
* 验证实体对象是否为空
* 如果对象属性为空,则判断该对象为空。
*
* @param bean
* @return
*/
public static boolean isEmpty(Object bean) {
PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(bean);
for (PropertyDescriptor origDescriptor : origDescriptors) {
String name = origDescriptor.getName();
if ("class".equals(name)) {
continue;
}
if (PropertyUtils.isReadable(bean, name)) {
try {
Object value = PropertyUtils.getSimpleProperty(bean, name);
if (value == null) {
continue;
} else {
return false;
}
} catch (java.lang.IllegalArgumentException ie) {
;
} catch (Exception e) {
;
}
}
}
return true;
}
---------------------
作者:Nihility/
来源:CSDN
原文:https://blog.csdn.net/qq724581322/article/details/70308325
版权声明:本文为博主原创文章,转载请附上博文链接!