Loading

LocalDateTime接收页面date

1. 数据库类型

  • 数据库采用datetime类型

2. 实体类类型

  • 因为采用mybatis的自动生成代码,会默认将datetime生成LocalDateTime

3.实体类加上两个注解

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

4. 页面

  • 页面数据:2021-01-27 21:37:50

总结:

  • 当时查阅了好多博客 只加了一个注解,每次运行都会出错:
Field error in object 'article' on field 'issueDate': rejected value [2021-01-27 21:37:50]; codes [typeMismatch.article.issueDate,typeMismatch.issueDate,typeMismatch.java.time.LocalDateTime,typeMismatch]; 
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [article.issueDate,issueDate]; 
arguments []; default message [issueDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property 'issueDate';
 nested exception is org.springframework.core.convert.ConversionFailedException: 
Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat java.time.LocalDateTime] for value '2021-01-27 21:37:50'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2021-01-27 21:37:50]]]
  • 意思是说string类型无法转换为LocalDateTime类型
posted @ 2021-01-27 21:42  hanlin-hl  阅读(658)  评论(0编辑  收藏  举报