免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
LocalDateTime去掉T

最近在使用阿里巴巴的fastjson反序列化對(duì)象的時(shí)候,對(duì)象里面時(shí)間格式屬性總是會(huì)多了一個(gè)T

 2021-1-09T18:29:09.097

這個(gè)T是啥國(guó)際標(biāo)準(zhǔn),但是我們的前端又不需要這個(gè)T,所以就要想辦法去掉T。

先看代碼

1、添加 LocalDateTimeSerializerConfig ,這個(gè)照搬過(guò)去就行了

 1 package com.dt.cloud.config;
 2 
 3 import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
 4 import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
 5 import org.springframework.context.annotation.Bean;
 6 import org.springframework.context.annotation.Configuration;
 7 import java.time.LocalDateTime;
 8 import java.time.format.DateTimeFormatter;
 9 
10 /**
11  * @Description: 去掉LocalDateTime帶T的問(wèn)題
12  * @author: Zhang Chonghu
13  * @Date: 2021/1/27 9:51
14  * @Copyright: Xi'an Dian Tong Software Co., Ltd. All Rights Reserved.
15  * @Version 1.0
16  */
17 @Configuration
18 public class LocalDateTimeSerializerConfig {
19     @org.springframework.beans.factory.annotation.Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
20     private String pattern;
21     @Bean
22     public LocalDateTimeSerializer localDateTimeDeserializer() {
23         return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern));
24     }
25     @Bean
26     public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
27         return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeDeserializer());
28     }
29 
30 }

 

在給小白們看看這個(gè)目錄,我們項(xiàng)目是有個(gè)config包專門管理這些config配置類的

 

 

2、做完配置,就要做一些代碼的操作了

 

 1     @JSONField(name="CreateTime")
 2     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
 3     private LocalDateTime createTime;
 4 
 5     @JSONField(name="CreateBy")
 6     private Integer createBy;
 7 
 8     @JSONField(name="ChangeTime")
 9     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
10     private LocalDateTime changeTime;

 

注意,我這兩個(gè)時(shí)間屬性是在Queue實(shí)體類中的,這里就貼這兩個(gè)屬性的代碼出來(lái)。這里要做的就是加上@JsonFormat,上圖

 

 

3、重點(diǎn)來(lái)了,注意看,我是先重?cái)?shù)據(jù)庫(kù)中查詢出queue這個(gè)對(duì)象,在利用阿里巴巴直接序列化這個(gè)queue對(duì)象

 

 

這里要說(shuō)明的是,因?yàn)闃I(yè)務(wù)需要,我要把整個(gè)對(duì)象返回,所以要序列化這個(gè)對(duì)象,再序列化那兩個(gè)時(shí)間屬性,如果我們只需要時(shí)間屬性,不需要其他屬性,直接序列化時(shí)間屬性返回就行了。

0k,下課?。?!

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
為什么建議使用你 LocalDateTime ,而不是 Date?
Jaskson精講第6篇-自定義JsonSerialize與Deserialize實(shí)現(xiàn)數(shù)據(jù)類型轉(zhuǎn)換
java 關(guān)于時(shí)間返回結(jié)果與參數(shù)的注解@DatetimeFormat和@JsonFormat
問(wèn)題:Cannot deserialize value of type `java.util.Date` from String “2020
ssm前后臺(tái)日期類型互相轉(zhuǎn)換
jackson中@JsonProperty、@JsonIgnore等常用注解總結(jié)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服