栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;

报400:为数据类型不匹配:

时间的类型在路径url中传来是String类型的

可以在controller层加上这个注解转换String为java.util.Date

@DateTimeFormat(pattern = "yyyy-MM-dd") Date begin
 @GetMapping
    public List listAll(@RequestParam("begin") @DateTimeFormat(pattern = "yyyy-MM-dd") Date beginTime, @RequestParam("end") @DateTimeFormat(pattern = "yyyy-MM-dd")Date endTime){
        System.out.println("beginTime"+beginTime);
        System.out.println("endTime:"+endTime);
        return demandClient.queryAllDemands(beginTime, endTime);
    }

图中的Date BeginTime; 如果前端的参数不是beginTime,而是begin需要在@RequestParam中定义为begin.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/301005.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号