论坛首页 Java版 Spring

Spring MVC模式中日期格式設定

浏览 357 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-04-18 关键字: 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));
    }


}
   
论坛首页 Java版 Spring

跳转论坛:
JavaEye推荐