// 获取控制字段列表
public static String[] getNullPropertyNames(Object source) {
  final BeanWrapper src = new BeanWrapperImpl(source);
  PropertyDescriptor[] pds = src.getPropertyDescriptors();
  Set<String> emptyNames = new HashSet<String>();
  for(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);
}


// 新增字段拷贝,只复制不为空的字段
LimitRuleDO entity = new LimitRuleDO();
LimitRuleCommonDo limitRuleCommonDo = new LimitRuleCommonDo();
// 获取空值字段
String[] names = getNullPropertyNames(limitRuleCommonDo);
// 忽略空值字段
BeanUtils.copyProperties(limitRuleCommonDo,entity,names);

相关文章:

  • 2021-11-15
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-07-01
猜你喜欢
  • 2022-12-23
  • 2021-08-22
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案