使用@DateTimeFormat注解

使用@DateTimeFormat(pattern = “yyyy-MM-dd”)注解,但是页面传入"2020-01-01",Java后端出现问题:Failed to convert value of type ‘java.lang.String’ to required type ‘java.util.Date’

在spring配置中添加:
<mvc:annotation-driven></mvc:annotation-driven>
这个配置表示:
会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)

参考链接:
https://www.cnblogs.com/shuo1208/p/5552134.html
https://blog.csdn.net/qq_34160679/article/details/76401576

猜你喜欢

转载自blog.csdn.net/Bruce_Zhang0828/article/details/106142086