获取对象属性为null的字段名称
作者:
_浅墨_ | 来源:发表于
2023-01-30 15:00 被阅读0次 /***
* 获取为null的字段
* @param source
* @return java.lang.String[]
**/
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
if (srcValue instanceof List && CollectionUtils.isEmpty((Collection<?>)srcValue)) {
emptyNames.add(pd.getName());
}
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
本文标题:获取对象属性为null的字段名称
本文链接:https://www.haomeiwen.com/subject/npbmhdtx.html
网友评论