BeanUtils copyProperties API忽略null和特定属性 [英] BeanUtils copyProperties API to ignore null and specific propertie

查看:703
本文介绍了BeanUtils copyProperties API忽略null和特定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring的 BeanUtils.copyProperties()提供了在复制bean时忽略特定属性的选项:

Spring's BeanUtils.copyProperties() provides option to ignore specific properties while copying beans:

public static void copyProperties(Object source,
                 Object target,
                 String[] ignoreProperties) throws BeansException

Apache Commons BeanUtils是否提供类似的功能?

Does the Apache Commons BeanUtils provide a similar feature?

使用Spring的<$ c时也可以忽略空值$ c> BeanUtils.copyProperties(),我在Commons BeanUtils中看到这个功能:

Also is it possible to ignore null values while using Spring's BeanUtils.copyProperties(), I see this feature with Commons BeanUtils:

Date defaultValue = null;
DateConverter converter = new DateConverter(defaultValue);
ConvertUtils.register(converter, Date.class);

我可以用Spring的BeanUtils实现相同的效果吗?

Can I achieve the same with Spring's BeanUtils?

推荐答案

如果要忽略 null -value,则必须在复制属性之前使用以下代码行:

If you want to ignore null-value you have to do it with the following line of code before copying properties:

BeanUtilsBean.getInstance().getConvertUtils().register(false, false, 0);

这篇关于BeanUtils copyProperties API忽略null和特定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆