spring笔记-PropertyValue

2018-06-03  本文已影响581人  兴浩

参考:
spring笔记-PropertyAccessor

1.PropertyValue

以对象的方式存储健值对,比存储在map会更加灵活

/**
 * Object to hold information and value for an individual bean property.
 * Using an object here, rather than just storing all properties in
 * a map keyed by property name, allows for more flexibility, and the
 * ability to handle indexed properties etc in an optimized way.
 *
 * <p>Note that the value doesn't need to be the final required type:
 * A {@link BeanWrapper} implementation should handle any necessary conversion,
 * as this object doesn't know anything about the objects it will be applied to.
 */
@SuppressWarnings("serial")
public class PropertyValue {
}

2.PropertyValues

即PropertyValue的集合管理类,MutablePropertyValues是其实现类

/**
 * Holder containing one or more {@link PropertyValue} objects,
 * typically comprising one update for a specific target bean.
 */
public interface PropertyValues {
}

3.测试代码

    @Test
    public void testValid() throws Exception {
        MutablePropertyValues pvs = new MutablePropertyValues();
        pvs.addPropertyValue(new PropertyValue("forname", "Tony"));
        pvs.addPropertyValue(new PropertyValue("surname", "Blair"));
        pvs.addPropertyValue(new PropertyValue("age", "50"));
        
        assertTrue("Contains 3", pvs.getPropertyValues().length == 3);
        assertTrue("Contains forname", pvs.contains("forname"));
        assertTrue("Contains surname", pvs.contains("surname"));
        assertTrue("Contains age", pvs.contains("age"));
        assertTrue("Doesn't contain tory", !pvs.contains("tory"));
    }
上一篇 下一篇

猜你喜欢

热点阅读