zoukankan      html  css  js  c++  java
  • Springmvc配置时间日期转换

    1.局部日期转换

      

    @Controller
    public class ProductController{
        @RequestMapping(value="/test/springmvc.do")
        public String test(String name,Date birthday){
            System.out.println(name+birthday);
            return "";    
        }
        //局部性的转换
        @InitBinder
        public void initBinder(WebDataBinder binder, WebRequest request) {
            // TODO Auto-generated method stub
            //转换日期格式
             DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,true));
        }
    }

    2.全局性的时间转换

    1).在springmvc.xml添加配置

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">    
        <!-- 日期格式转换 -->    
        <property name="webBindingInitializer">    
            <bean class="cn.itcast.core.web.DateConverter" />    
        </property>    
    </bean>

    2).编写 DateConverter

    public class DateConverter implements WebBindingInitializer {    
        
        public void initBinder(WebDataBinder binder, WebRequest request) {       
             DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat,true));   
        }
    }
  • 相关阅读:
    博客推荐
    2018
    2018
    学习推荐-Postgresql学习手册
    学习推荐-Redis学习手册
    odoo开发笔记 -- odoo源码解析
    前沿技术相关
    odoo开发笔记-tree列表视图拖拽排序
    odoo开发笔记-日期时间相关操作
    odoo开发笔记 -- 官方模块一览表
  • 原文地址:https://www.cnblogs.com/menbo/p/9774066.html
Copyright © 2011-2022 走看看