DataBinderTests.java 文件源码

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

项目:spring4-understanding 作者:
@Test
public void testCustomEditorForPrimitiveProperty() {
    TestBean tb = new TestBean();
    DataBinder binder = new DataBinder(tb, "tb");

    binder.registerCustomEditor(int.class, "age", new PropertyEditorSupport() {
        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue(new Integer(99));
        }

        @Override
        public String getAsText() {
            return "argh";
        }
    });

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("age", "");
    binder.bind(pvs);

    assertEquals("argh", binder.getBindingResult().getFieldValue("age"));
    assertEquals(99, tb.getAge());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号