BeanUtils copyProperties 过滤null记录下
来源:互联网 发布:淘宝店家花呗怎么开通 编辑:程序博客网 时间:2024/06/05 06:05
/** * Created by bls on 2016/6/16. */public class BeanUtils extends org.springframework.beans.BeanUtils { public static void copyProperties(Object source, Object target) throws BeansException { Assert.notNull(source, "Source must not be null"); Assert.notNull(target, "Target must not be null"); Class<?> actualEditable = target.getClass(); PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable); for (PropertyDescriptor targetPd : targetPds) { if (targetPd.getWriteMethod() != null) { PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName()); if (sourcePd != null && sourcePd.getReadMethod() != null) { try { Method readMethod = sourcePd.getReadMethod(); if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } Object value = readMethod.invoke(source); // 这里判断以下value是否为空 当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等 if (value != null) { Method writeMethod = targetPd.getWriteMethod(); if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(target, value); } } catch (Throwable ex) { throw new FatalBeanException("Could not copy properties from source to target", ex); } } } } }}
1 0
- BeanUtils copyProperties 过滤null记录下
- BeanUtils.copyProperties忽略null值
- BeanUtils.copyProperties方法遇到null值问题
- BeanUtils.copyProperties方法遇到null值问题
- BeanUtils.copyProperties方法遇到null值问题
- beanUtils.copyProperties
- BeanUtils.copyProperties
- BeanUtils.copyProperties
- BeanUtils.copyProperties()
- BeanUtils.copyProperties
- BeanUtils.copyProperties&&PropertyUtils.copyProperties
- BeanUtils.copyProperties()与PropertyUtils.copyProperties()
- BeanUtils.copyProperties()在不同包下,用法不同!!! 切记!!!
- BeanUtils.copyProperties() 用法
- BeanUtils.copyProperties() 用法
- BeanUtils.copyProperties()的用法
- BeanUtils.copyProperties()方法
- BeanUtils.copyProperties()的用法
- Android Studio 插件 Statistic
- TCP与UDP的区别
- 1/72th of an inch
- java System.arraycopy
- 子类虚函数表(包括虚函数+函数)
- BeanUtils copyProperties 过滤null记录下
- Lua学习笔记之字符串及模式匹配
- 剑指offer-面试题20:顺时针打印矩阵
- java生成XML文档操作
- 微信公众号推送地图
- 对Promise的一些理解
- Shiro权限管理框架(1)
- git 常用指南
- 气化器中BOG和EAG分别是什么意思?