CustomEditorTests.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:spring4-understanding 作者:
@Test
public void testIndexedPropertiesWithListPropertyEditor() {
    IndexedTestBean bean = new IndexedTestBean();
    BeanWrapper bw = new BeanWrapperImpl(bean);
    bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            List<TestBean> result = new ArrayList<TestBean>();
            result.add(new TestBean("list" + text, 99));
            setValue(result);
        }
    });
    bw.setPropertyValue("list", "1");
    assertEquals("list1", ((TestBean) bean.getList().get(0)).getName());
    bw.setPropertyValue("list[0]", "test");
    assertEquals("test", bean.getList().get(0));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号