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); } } }
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14