1. 数据库类型
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类型