使用@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

posted @   搬砖的孟达  阅读(90)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示