关于Date对象的属性编辑
1、继承PropertyEditorSupport类
2、在spring配置文件中定义
1、继承PropertyEditorSupport类
public class UtilsDatePropertyEditor extends PropertyEditorSupport {
private String format;
@Override
public void setAsText(String text) throws IllegalArgumentException {
System.out.println(text);
SimpleDateFormat sdf = new SimpleDateFormat(format);
try{
Date d = sdf.parse(text);
this.setValue(d);
}catch(Exception e){
e.printStackTrace();
}
}
public void setFormat(String format) {
this.format = format;
}
}
2、在spring配置文件中定义
<!-- 定义属性编辑器 -->
<bean id="CustomEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Date">
<bean class="com.twh.spring.UtilsDatePropertyEditor">
<property name="format" value="yyyy-MM-dd"/>
</bean>
</entry>
</map>
</property>
</bean>