JAVA全系列 教程
3762个小节阅读:7094.4k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
org.springframework.beans.PropertyValue 是Spring框架对Bean属性的抽象类。一个PropertyValue对应Bean中一个属性。所以我们可以看到MutablePropertyValues有参构造方法参数是List<PropertyValue>
,因为每个类都可能有多个属性。
xxxxxxxxxx
public MutablePropertyValues(@Nullable List<PropertyValue> propertyValueList)
PropertyValue使用起来也很简单,通过构造方法,可以直接设定属性名及值是什么。
xxxxxxxxxx
public PropertyValue(String name, @Nullable Object value)
所以当使用PropertyValue进行数据绑定时的代码和上面使用Map进行数据绑定的代码,就把Map换成了List<PropertyValue>
xxxxxxxxxx
@Test
void testPropertyValue(){
People peo= new People();
List<PropertyValue> list = new ArrayList<>();
list.add(new PropertyValue("id","2"));
list.add(new PropertyValue("name","smallming"));
PropertyValues pv =new MutablePropertyValues(list);
DataBinder dataBinder = new DataBinder(peo,"people");
dataBinder.bind(pv);
System.out.println(peo);
}