BeanUtils.copyProperties默认没有提供设置忽略null属性。
用下面的类可以,直接拿过去用。
public class CopyUtils { 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) ; } public static void copyProperties (Object src , Object target) { BeanUtils. copyProperties (src , target , getNullPropertyNames (src)) ; } }
凌云 2018-11-23
凌云 2018-11-23
伍仔 2017-02-16
虎礁之恋 2020-01-12
hemsu 2022-02-21
乐高无限 2019-08-16
吟风 2017-02-03
泡泡 2016-10-15
伍仔 2016-09-09
hemsu 2021-10-30
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23
藏家389 2025-03-23