今天在做springboot项目时碰见一个小问题问题,是关于前段传来的日期是String类型,而后端需要的是LocalDateTime类型,错误如下:
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException:
Failed to convert value of type ‘java.lang.String’ to required type ‘java.time.LocalDateTime’;
org.springframework.core.convert.ConversionFailedException:
Failed to convert from type [java.lang.String] to type [java.time.LocalDateTime] for value ‘2022-06-21 00:00:00’;
java.lang.IllegalArgumentException:
Parse attempt failed for value [2022-06-21 00:00:00]。
解决办法:
只需要在yml文件中加入:
即可!!!!