feat: 任务开始页面,相关逻辑补充

This commit is contained in:
2025-07-08 09:20:31 +08:00
parent 72c9a0be65
commit 5df805cca7
7 changed files with 71 additions and 28 deletions
@@ -1,10 +1,12 @@
package com.guo.learningprogresstracker.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.guo.learningprogresstracker.config.serializer.LocalDateTimeSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import java.time.LocalDateTime;
@@ -14,11 +16,17 @@ import java.time.LocalDateTime;
@Configuration
public class JacksonConfig {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper mapper = builder.build();
// 注册自定义序列化器
SimpleModule module = new SimpleModule();
module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer());
mapper.registerModule(module);
// 关闭序列化为时间戳(使用字符串格式)
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return mapper;
}
}
@@ -10,8 +10,8 @@ import java.time.format.DateTimeFormatter;
public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
// 定义你希望使用的日期时间格式
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");;
// 修改为ISO 8601格式,末尾带Z,表示UTC时区
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
public LocalDateTimeSerializer() {
super(LocalDateTime.class);
@@ -22,9 +22,8 @@ public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {
if (value == null) {
gen.writeNull();
} else {
// 格式化LocalDateTime为字符串
// 这里假设LocalDateTime是UTC时间,直接格式化并加Z
String formattedDate = value.format(formatter);
// 将格式化后的字符串写入JSON流作为一个值
gen.writeString(formattedDate);
}
}