首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

BeanUtils.copyProperties 在copy Integer类型有关问题

2013-08-29 
BeanUtils.copyProperties 在copy Integer类型问题在使用apache common 包中BeanUtils.copyProperties 中

BeanUtils.copyProperties 在copy Integer类型问题

在使用apache common 包中BeanUtils.copyProperties 中如果对象中有Integer 类型的属性值为空,copy之后值变成了0,如想解决这个问题,则

在当前类中加载以下代码可解决

// 可以通过转换器来设置为null时的默认转换值。

static {

ConvertUtils.register(new LongConverter(null), Long.class);

ConvertUtils.register(new ShortConverter(null), Short.class);

ConvertUtils.register(new IntegerConverter(null), Integer.class);

ConvertUtils.register(new DoubleConverter(null), Double.class);

ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);

}

热点排行