zoukankan      html  css  js  c++  java
  • Spring mvc时间格式处理

    spring mvc中,如果时间格式是yyyy-MM-dd,传入后台会报错,要增加一些配置才可以。

    1.修改spring-mvc.xml,增加org.springframework.format.support.DefaultFormattingConversionService

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
        <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
            <property name="messageConverters">
                <list>
                    <ref bean="mappingFastJsonHttpMessageConverter"/> <!-- JSON转换器 -->
                </list>
            </property>
            <property name="webBindingInitializer">
                <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                    <property name="conversionService" ref="conService" />
                </bean>
            </property>
        </bean>
    
        <bean id="conService" class="org.springframework.format.support.DefaultFormattingConversionService"/>

    2.在实体属性处增加DateTimeFormat注解

     @DateTimeFormat(pattern = "yyyy-MM-dd")
        private Date reqisterDate;
  • 相关阅读:
    POJ2352
    POJ 2524 并查集
    A POJ1611
    树状dp--B
    spring mvc实现文件上传与下载
    Joda-Time
    JAVA对象与JSON之间的转换
    jackson-databind注解
    JPA注解
    springMVC、spring、jpa、springData整合配置
  • 原文地址:https://www.cnblogs.com/Gyoung/p/5458163.html
Copyright © 2011-2022 走看看