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;
如果我的文章对你有帮助,就点一下推荐吧.(*^__^*)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步