swagger提供的默认参数格式大概是下面这个样子
2021-11-24T08:41:36.357Z
直接传入这个格式的字符串,服务端会报错
Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String "2021-11-24T08:41:36.357Z": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2021-11-24T08:41:36.357Z' could not be parsed at index 10
在入参的DTO对应的LocalDateTime类型参数上标注一个jackson的注解
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
当然,不一定是上面这种格式的,根据自己的需求调整。
在测试时,入参可以传入2021-11-24 00:00:00
格式的数据,就不会报错,并且能够正确解析。