【发布时间】:2021-03-14 14:04:31
【问题描述】:
我有一个带有请求参数的 Rest Controller:
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") ZonedDateTime startDate
当我将数据发布到我的控制器时:
startDate=2020-12-02T18:07:33.251Z
但是我收到 400 Bad Request 错误:
2020-12-02 18:20:32.428 WARN 26384 --- [nio-2000-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.time.ZonedDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.ZonedDateTime] for value '2020-12-02T18:07:33.251Z'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2020-12-02T18:07:33.251Z]]
【问题讨论】:
-
对不起,'Z'不见了,应该这么简单吗……
-
@Turo 这是一个错字。
-
'T'这些引号是干什么用的? -
@fukanchik ISO 8601 定义以“T”分隔的日期和时间。
-
@kamaci 我又看了一遍,在 ISO 8601 中
T周围没有'引号。
标签: java spring spring-boot zoneddatetime