文章出處

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;

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()