mybatis-plus3整合到springboot时,返回json结果集到前端,时间格式中,会多个T的问题处理
- 第一步:添加一个时间格式处理类
CustomDateSerializer.java
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class CustomDateSerializer extends JsonSerializer<LocalDateTime> {
@Override
public void serialize(LocalDateTime value, JsonGenerator jgen,
SerializerProvider provider)
throws IOException {
if (value != null) {
jgen.writeString(value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}
}
}
- 第2步:在实体类上,添加如下注解
@JsonSerialize(using = CustomDateSerializer.class)
private LocalDateTime updateDate;