zoukankan      html  css  js  c++  java
  • @InitBinder的作用

    在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支持这个格式的转换,所以必须要手动配置, 自定义数据类型的绑定才能实现这个功能。

    比较简单的可以直接应用springMVC的注解@initbinder和spring自带的WebDataBinder类和操作。

    @InitBinder
        protected void initBinder(WebDataBinder binder) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
        }

    还要在springMVC配置文件中加上:

    <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 请求映射 -->
        <bean
                class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
        <bean
                class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
        </bean>

    这样就可以直接将上传的日期时间字符串绑定为日期类型的数据了
    ————————————————
    版权声明:本文为CSDN博主「大智_」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/sinat_35663368/article/details/52636417

  • 相关阅读:
    火车进出栈问题(卡特兰数)
    HDU 4699 Editor (对顶栈)
    HDU 6430 TeaTree (线段树合并)
    Exam 4895 Crowd Control
    Exam 4894 Booming Business
    8377: Playoff
    hdu 6345 Problem J. CSGO
    HDU 6437 Problem L.Videos
    Making the Grade
    poj2279——Mr. Young's Picture Permutations
  • 原文地址:https://www.cnblogs.com/lm970585581/p/13066517.html
Copyright © 2011-2022 走看看