• 17_10_13 SSM中日期传递格式转化


    两种方式:

    局部的:在Controller层
    @Controller
    public class ProductController {
    	
    	@InitBinder
    	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));
    		
    	}
    	
    
    全局的:在springmvc的xml中
    <!-- 配置全局日期转换器 -->
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    		<property name="webBindingInitializer">
    			<bean class="cn.itcast.core.web.CustomDateEdtor"/>
    		</property>
    	</bean>
    
    这个cn.itcast.core.web.CustomDateEdtor是自己写的类
    public class CustomDateEdtor implements WebBindingInitializer {
    
    	@Override
    	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));
    	}
    
    }
    

    [参考视频:新巴巴运动网(spring+springmvc+mybatis)day76_babSport 第二天2springmvc日期配置(全局+局部)_]

  • 相关阅读:
    杭电2054
    M1/M2总结
    软件开发相关的读书笔记 问题与方法
    代码复审1234跟我一起来
    电梯调度算法简述
    Pair_Work Project
    读书笔记摘录:
    Individual Project
    个人阅读作业——软件工程M1/M2的总结
    个人阅读作业2
  • 原文地址:https://www.cnblogs.com/du1991/p/7663668.html
Copyright © 2020-2023  润新知