关于使用LocalDateTime类型接收参数报错

关于使用LocalDateTime类型接收参数报错

需要的参数

@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDateTime startDateTime

传递的参数: 2023-03-30

报错:
Failed to convert property value of type ‘java.lang.String’ to required type ‘java.time.LocalDateTime’ for property…

最后发现如果使用LocalDateTime来接收的话,需要年月日时分秒
例如: 2023-03-30 15:29:00

如果只传递年月日的话需要使用LocalDate

@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate

这样就没问题了!

猜你喜欢

转载自blog.csdn.net/weixin_42947972/article/details/129859041