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

Posted SmallCuteMonkey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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<Demand> 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.

以上是关于Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;的主要内容,如果未能解决你的问题,请参考以下文章

springboot 提交时间字符串报错 Failed to convert property value of type ‘java.lang.String‘ to required ‘Date‘

springboot 提交时间字符串报错 Failed to convert property value of type ‘java.lang.String‘ to required ‘Date‘

springboot 提交时间字符串报错 Failed to convert property value of type ‘java.lang.String‘ to required ‘Date‘

message [Failed to convert property value of type [java.lang.String] to required type [java.util.Dat

Failed to convert property value of type ‘java.lang.String‘ to required type ‘int‘ for property

Failed to convert property value of type ‘java.lang.String‘ to required type ‘int‘ for property(代码片段