BeanUtils 转换器将Long ,Integer等字段的默认值设置为null
来源:互联网 发布:淘宝特卖网如何上商品 编辑:程序博客网 时间:2024/05/22 06:34
今天在使用BeanUtils时发现copyProperties方法从Long到Long复制的时候,原字段为null,结果拷贝过去之后目标字段变成了0,这不是我想要的结果,在网上搜索了一下,是可以通过转换器来设置为null时的默认转换值。
于是我就把一些常用的数字型的字段的默认转换值设置成了null,然后再使用BeanUtils.copyProperties拷贝字段,Long,Integer等字段为null的就不会默认转换成0了。
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);}
于是我就把一些常用的数字型的字段的默认转换值设置成了null,然后再使用BeanUtils.copyProperties拷贝字段,Long,Integer等字段为null的就不会默认转换成0了。
- BeanUtils 转换器将Long ,Integer等字段的默认值设置为null
- BeanUtils 转换器将Long ,Integer等数字类型的默认值设置为null
- BeanUtils 转换器将Long ,Integer等数字类型的默认值设置为null
- BeanUtils.populate 转换器将 integer等字段的默认值为null
- BeanUtils.copyProperties做copy的时候,Long 字段会设置为null
- Power Designer将字段默认值设置为字符串的空
- 为已存在的字段(Null)添加约束,设置默认值为0
- BeanUtils.copyProperties 如果Integer 或Long 为null 默认赋值0
- BeanUtils.copyProperties 如果Integer 或Long 为null 默认赋值0
- 有关apache包里面的BeanUtils.copyProperties 字段类型为Integer或者Double时,自动赋值为默认值的问题随笔
- int的默认值为0,而Integer的默认值为null
- 向数据库中插入默认值为null的字段
- 对表中的字段设置了默认值,新增记录后却发现该字段为null
- JPA为字段设置默认值
- SpringmvcJSON转换器MappingJackson2HttpMessageConverter设置对值为null的处理
- mysql查询时给值为null的设置默认值
- 数据库,设置默认值为null setInc失败
- mysql 设置字段为null
- 在Service中获得WindowManager
- SAMSUNG的CMOS 图像传感器技术发展路线
- 网页中嵌入SWF的几种格式
- Linux 引导过程内幕
- Mozilla FireFox Gecko内核源代码解析(4.nsHTMLTokens)
- BeanUtils 转换器将Long ,Integer等字段的默认值设置为null
- 天空之城
- hibernateTemplate
- E1、CE1、T1、PRI、BRI知识介绍和配置
- 硬盘分区任我动
- 【PB】如何触发带参数的自定义事件?
- Javascript框架之dhtmlXGrid
- 找不到工作怎么办
- python与shell的完美结合