Spring如何自定义属性编辑器,其实这个问题也不难,步骤如下。
方法/步骤
1
首先,创建一个类继承java.beans.PropertyEditorSupport。重写其方法。setAsText(String Text):public void setAsText(String Text) throws IllegalArgumentException {System.out.println(“UtilDatePropertyEditor.setAsText() text=”+Text);SimpleDateFormat sdf = new SimpleDateFormat(format);try{Date d = sdf.parse(Text);this.setValue(d);}catch(ParseException e){e.printStackTrace();}}
2
然后,再在配置文件中配置:< bean id=”customerEditorConfigure” class=”org.springframework.beans.factory.config.CustomEditorConfigurer”>< property name=”customEditors”>< map>< entry key=”java.util.Date”>< bean class=”com.zhangjie.spring.UtilDatePropertyEditor”>< /entry>< /map>< /property>< /bean>
3
最后在配置文件中配置java.util.Date属性都会将字符串转为时间。
上一篇:保定白洋淀怎么游玩?
下一篇:1688一件代发搬运图片发布宝贝