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));   
        }
    }
  • 相关阅读:
    ORM之F和Q
    ORM查询
    Django
    jQuery基础
    DOM和BOM
    saas baas paas iaas 的理解
    分布式架构的演进过程
    tomcat 配置https 证书
    idea 学习总结
    简单数据库连接池-总结
  • 原文地址:https://www.cnblogs.com/menbo/p/9774066.html
Copyright © 2011-2022 走看看