1.获取source中值为null的属性
public class PropertyNameNull {
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());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
}
2.使用BeanUtils.copyProperties(source, target,string ...ignoreProerties) 方法
String [] str= PropertyNameNull.getNullPropertyNames(dto);
BeanUtils.copyProperties(dto, rcd,str);