2008-03-26

Spring MVC模式中日期格式設定

关键字: mvc
首先在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));
    }


}
评论
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

morris
搜索本博客
存档
最新评论