springmvc datetimeformat 使用时需要配置么
发布网友
发布时间:2022-08-15 06:03
我来回答
共1个回答
热心网友
时间:2023-09-13 07:28
需要引入相关,并jar配置webBindingInitializer
:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<!-- json转换器 -->
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
</list>
</property>
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService">
<bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean>
</property>
</bean>
</property>
</bean>
后可如此使用:
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date dateFrom;