没什么JAVA BEAN基础,看了看spring的beanwrapper
大概了解了propertyEditor的工作方式,主要关注convert string to object
记下来,省得用到时再乱找

步聚:

1,写出你要转换的bean及对应的propertyEditor(如:Person=>PersonEditor)
2,用PropertyEditorManager注册:
[code:1]
PropertyEditorManager.registerEditor(Person.class,PersonEditor.class)
[/code:1]
3,你得到一个要转换的string,查出想转换成的bean对映的propertyEditor
如:
[code:1]
PropertyEditorManager.findEditor(Person.class)
[/code:1]
4,你知道啦,调用你找到的editor的setAsText(String)
如:
[code:1]
editor.setAsText("23,liunix");
[/code:1]
5,在你属性宿主bean上调用setter
如:
[code:1]
personManager.setPerson((Person)editor.getValue())
[/code:1]
ok!


另外,可以省去PropertyEditorManager.registerEditor注册方法有
1,
你要转换的bean及对应的propertyEditor在同一个包内,而且名字形如:Person=>Person+Editor来定义两个类的名字,
2,名称对应,不在一个包内
调用PropertyEditorManager.setEditorSearchPath(String[])
其中string[]指定你editor的包名即可
评论
lsy 2007-01-26
好啊.我也基本有个了解了.谢谢
发表评论

您还没有登录,请登录后发表评论

liuyifan.com
搜索本博客
最近加入圈子
最新评论
评论排行榜