Model
@ApiModelProperty(value = "日期")
@JsonFormat(pattern = "yyyy-MM-dd", shape = JsonFormat.Shape.STRING)
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDateTime dataTime;
用的代码生成器,所有的日期类型都是 LocalDateTime,其实这个地方用 LocalDate 就可以了
请求
{
"dataTime":"2021-03-12"
}
错误
{
"code": 1,
"msg": "JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String \"2021-03-12\": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2021-03-12' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2021-03-12 of type java.time.format.Parsed; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String \"2021-03-12\": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2021-03-12' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2021-03-12 of type java.time.format.Parsed\n at [Source: (PushbackInputStream); line: 2, column: 16] (through reference chain: com.qctc.bdss.marketanalysis.entity.MarketLineBlockAhead[\"dataTime\"])",
"data": null
}
请问怎么通过注解的方式将 yyyy-MM-dd 格式的字符串转换为 LocalDateTime
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.