propertyEditor工作方式

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

步聚:

1,写出你要转换的bean及对应的propertyEditor(如:Person=>PersonEditor)
2,用PropertyEditorManager注册:

PropertyEditorManager.registerEditor(Person.class,PersonEditor.class);

3,你得到一个要转换的string,查出想转换成的bean对映的propertyEditor
如:

PropertyEditorManager.findEditor(Person.class);

4,你知道啦,调用你找到的editor的setAsText(String)
如:

editor.setAsText("23,liunix");;

5,在你属性宿主bean上调用setter
如:

personManager.setPerson((Person);editor.getValue(););

ok!


另外,可以省去PropertyEditorManager.registerEditor注册方法有
1,
你要转换的bean及对应的propertyEditor在同一个包内,而且名字形如:Person=>Person+Editor来定义两个类的名字,
2,名称对应,不在一个包内
调用PropertyEditorManager.setEditorSearchPath(String[])
其中string[]指定你editor的包名即可
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值