時間解析エラー

エラーの詳細

原因: java.time.format.DateTimeParseException: Text '2023-11-20 11:00:00' could not parsed at index 10 
   at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) 
   at java .time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) 
   at java.time.LocalDateTime.parse(LocalDateTime.java:492) 
   com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java) :100) 
   ... 103 共通フレーム省略

フロントエンドから渡されるパラメータは「2023-11-20 11:00:00」です

バックエンドは Java であり、Java は LocalDateTime を使用して受信します

@ApiModelProperty(value = "sign time")
プライベート LocalDateTime signTime;

エラーの理由は、パターンが指定されておらず、デフォルトで使用されるため、デフォルトの形式、つまり: が使用されるためです。これは次のようになりますDateTimeFormatter.ISO_LOCAL_DATE_TIME: 2011-12-03T10:15:30.

解決策、注釈を追加

   @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")

参照ドキュメント: Jackson の解析エラーを解決する "Cannot deserialize value of type `java.time.LocalDateTime` from String … could not be parsed at index 10" — Freedom House ブログ

おすすめ

転載: blog.csdn.net/wangwenzhe222/article/details/130481469