Spring mvc時間格式處理

spring mvc中,若是時間格式是yyyy-MM-dd,傳入後臺會報錯,要增長一些配置才能夠。web

1.修改spring-mvc.xml,增長org.springframework.format.support.DefaultFormattingConversionServicespring

<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註解spring-mvc

 @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date reqisterDate;
相關文章
相關標籤/搜索