【发布时间】:2022-11-26 04:00:26
【问题描述】:
将 spring-boot 从 2.2 升级到 3.0 后,LocalDateTime 查询参数的反序列化开始失败。
这是控制器的签名:
public Mono<QueryResult> index(@PathVariable String breakdown, QueryParams queryParams)
QueryParams 在哪里
@Data
public class QueryParams {
@NotBlank
@DateTimeFormat(pattern = "YYYYMMddHHmmss")
private LocalDateTime from;
@NotBlank
@DateTimeFormat(pattern = "YYYYMMddHHmmss")
private LocalDateTime to;
此代码在 spring boot 2.2 中运行良好但在 3.0 中抛出:
2022-11-25 18:33:33 http-nio-8080-exec-8 - org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver WARN Resolved [org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors<EOL>Field error in object 'queryParams' on field 'from': rejected value [20221001000000]; codes [typeMismatch.queryParams.from,typeMismatch.from,typeMismatch.org.joda.time.LocalDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [queryParams.from,from]; arguments []; default message [from]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.LocalDateTime' for property 'from'; Cannot convert value of type 'java.lang.String' to required type 'org.joda.time.LocalDateTime' for property 'from': no matching editors or conversion strategy found]<EOL>Field error in object 'queryParams' on field 'to': rejected value [20221031000000]; codes [typeMismatch.queryParams.to,typeMismatch.to,typeMismatch.org.joda.time.LocalDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [queryParams.to,to]; arguments []; default message [to]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.joda.time.LocalDateTime' for property 'to'; Cannot convert value of type 'java.lang.String' to required type 'org.joda.time.LocalDateTime' for property 'to': no matching editors or conversion strategy found]]
【问题讨论】:
标签: spring-boot