spring定制属性编辑器

<!-- 自定义编辑器配置器 -->
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<!-- 自定义编辑器集 -->
<property name="customEditors">
<map>
<entry key="cn.itcast.spring.scatter.Address">
<bean class="cn.itcast.spring.editor.AddressEditor"/>
</entry>
</map>
</property>
</bean>

<bean id="scatter" class="cn.itcast.spring.scatter.Scatter">
<property name="comAddress">
<bean class="cn.itcast.spring.scatter.Address">
<property name="province" value="jilin"/>
<property name="city" value="cc"/>
<property name="street" value="${jdbc.url}"/>
</bean>
</property>
<property name="homeAddress">
<value>jilin.cc.renmin.100000</value>
</property>
</bean>

public class Scatter {

private Address comAddress; // 公司住址
private Address homeAddress; // 家庭住址

public Address getComAddress() {
return comAddress;
}

public void setComAddress(Address comAddress) {
this.comAddress = comAddress;
}

public Address getHomeAddress() {
return homeAddress;
}

public void setHomeAddress(Address homeAddress) {
this.homeAddress = homeAddress;
}
}
public class AddressEditor extends PropertyEditorSupport {

public void setAsText(String text) throws IllegalArgumentException {
if (text != null && text.length() > 0) {
String[] ss = text.split("\\.");
if(ss.length>3) {
Address a = new Address();
a.setProvince(ss[0]);
a.setCity(ss[1]);
a.setStreet(ss[2]);
a.setZipCode(ss[3]);
setValue(a);
} else {
setValue(null);
}
} else {
setValue(null);
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值