Loading

LocalDateTime自动转化格式

开发中,遇到这样的问题。一个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;

 

参考自:

https://blog.csdn.net/zdyueguanyun/article/details/88740902

posted @ 2019-11-20 12:21  元宝爸爸  阅读(5918)  评论(0编辑  收藏  举报