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.

猜你喜欢

转载自blog.csdn.net/houzhicongone/article/details/120630220