开发中,遇到这样的问题。一个LocalDateTime类型的属性返回给前端是中间带T的格式,前端说转不了。
可以引入jackson包转换一下
<properties> <jackson.version>2.8.5</jackson.version> </properties> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>${jackson.version}</version> </dependency> <!-- 支持java8 localDate等新时间类型的序列化 --> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> <version>${jackson.version}</version> </dependency>
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime applicationTime;
参考自: