错误:
JSON parse error: Cannot deserialize value of type java.time.LocalDateTime
from String “1971-06-02 16:04:27”: Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text ‘1971-06-02 16:04:27’ could not be parsed at index 10; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.time.LocalDateTime
from String “1971-06-02 16:04:27”: Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text ‘1971-06-02 16:04:27’ could not be parsed at index 10
at [Source: (PushbackInputStream); line: 4, column: 15] (through reference chain: com.youming.shuiku.synthesis.dto.security.SecurityMaterialTrainDto[“trTime”])
原因就是json转换的时候出现的错误
解决方案:
提示: 在LocalDateTime 类型的字段上加@JsonFormat注解,如下:
解决问题。
上面的情况是传入的Json对象的时候,进行的格式转换。还有一种情况就是直接传递参数的时候进行的格式转换
这样前端直接传过来的参数就能够被接收