org.springframework.beans.Beanutils.copyProperties 原理
来源:互联网 发布:网络直播电视软件哪个好 编辑:程序博客网 时间:2024/05/21 06:26
org.springframework.beans.Beanutils.copyProperties 原理
BeanUtils. copyProperties(source,targe)原理:
- 根据source的属性来向target同名属性设值。
- 若target无该属性,则不设
- 名字相同,基本类型和封装类型可以完成映射
- 若target有source无,则target属性值为null(基本类型则为初始值,如int 为 0)
- 调用原理 target.set + source的属性名(source.get + source的属性名):所有source必须有get方法,target必须有set方法
下面是例子
import org.springframework.beans.BeanUtils;
public class BeanUtilsTest {
public static void main(String[] args) {
Source source = new Source() {{
setId(1111111);
}};
Target target = new Target();
BeanUtils.copyProperties(source,target);
System.out.println(source);
System.out.println(target);
}
}
class Source {
int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "Cat{" +
"id=" + id +
'}';
}
}
class Target {
// id换名 则无法赋值
Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return "Dog{" +
"id=" + id +
'}';
}
}
阅读全文
0 0
- org.springframework.beans.Beanutils copyProperties 原理
- org.springframework.beans.Beanutils.copyProperties 原理
- org.springframework.beans.BeanUtils.copyProperties方法的泛型问题。
- org.springframework.beans.BeanUtils
- 重写org.springframework.beans.BeanUtils的copyProperties(Object source,Object target)方法 从model复制属性到pojo中
- 【exception】java.lang.NoSuchMethodError: org.springframework.beans.Beans.BeanUtils
- org.springframework.beans.BeanUtils与org.apache.commons.beanutils.BeanUtils的区别
- java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass
- org.springframework.beans.TypeMismatchException:
- org.springframework.beans.NotWritablePropertyException
- org.springframework.beans.BeanInstantiationException
- org.springframework.beans.ConversionNotSupportedException:
- org.springframework.beans.NotWritablePropertyException
- org.springframework.beans.NotWritablePropertyException
- org.springframework.beans.ConversionNotSupportedException
- org.springframework.beans.NotWritablePropertyException
- org.springframework.beans.NotWritablePropertyException
- org.springframework.beans.NotWritablePropertyException
- 卡拉兹猜想
- Elasticsearch 5.6.3 通过script添加、删除数组元素
- rsync error(1503)分析:@ERROR: auth failed on module xxxx rsync error: error starting client-server
- 混合信号芯片成功实现PCB接地 第2部分:最小化信号路径串扰的设计---凯利讯半导体
- 将 Windows 虚拟机从非托管磁盘转换为托管磁盘
- org.springframework.beans.Beanutils.copyProperties 原理
- Ubuntu下 python3 安装Mayavi
- synchronize和lock锁如何选择
- python模块安装-Redis模块
- JavaScript 中字符串的操作
- Android 腾讯Bugly 热更新
- css选择器
- Java简单工具:UDP通讯工具类(测试使用)
- OC 协议和委托