首先在action-servlet.xml中配置如下:
具體的實現代碼如下:
<!-- property editor -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.morris.MyBindingInitializer"/>
</property>
</bean>
具體的實現代碼如下:
package com.morris;
/**
* @author morris
* @version 1.0 2008-03-26
*/
public class MyBindingInitializer implements WebBindingInitializer {
public void initBinder(WebDataBinder binder, WebRequest request) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); //可以設定任意的日期格式
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class,
new CustomDateEditor(dateFormat, true));
binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
}
}