TA的每日心情 | 开心 2021-12-13 21:45 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
|
首先,创建一个类继承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();
}
}
然后,再在配置文件中配置:
<!– 定义属性编辑器 –>
< 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”></bean>
< /entry>
< /map>
< /property>
< /bean>
最后在配置文件中配置java.util.Date属性都会将字符串转为时间。
<property name=”dateValue”>
< value>2012-10-24</value>
< /property>
|
|