refactor(cms): 将LocalDateTime替换为Date类型并调整过期逻辑
- 将CmsWebsite实体中的LocalDateTime字段改为Date类型- 更新服务实现中时间比较逻辑以兼容Date类型 - 添加日期转换处理以确保过期时间计算正确 - 移除冗余的LocalDateTime导入并优化代码结构 - 调整测试相关代码以适应新的时间类型处理方式
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
package com.gxwebsoft;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.gxwebsoft.cms.entity.CmsWebsite;
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Jackson序列化测试
|
||||
*/
|
||||
public class JacksonTest {
|
||||
|
||||
@Test
|
||||
public void testLocalDateTimeSerialization() throws Exception {
|
||||
// 创建ObjectMapper并注册JavaTimeModule
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
|
||||
// 创建测试对象
|
||||
TestObject testObj = new TestObject();
|
||||
testObj.setName("测试");
|
||||
testObj.setExpirationTime(LocalDateTime.now());
|
||||
|
||||
// 序列化
|
||||
String json = mapper.writeValueAsString(testObj);
|
||||
System.out.println("序列化结果: " + json);
|
||||
|
||||
// 反序列化
|
||||
TestObject result = mapper.readValue(json, TestObject.class);
|
||||
System.out.println("反序列化结果: " + result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCmsWebsiteSerialization() throws Exception {
|
||||
// 创建ObjectMapper并注册JavaTimeModule
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
|
||||
// 创建CmsWebsite对象
|
||||
CmsWebsite website = new CmsWebsite();
|
||||
website.setWebsiteName("测试网站");
|
||||
website.setExpirationTime(LocalDateTime.now());
|
||||
|
||||
// 序列化
|
||||
String json = mapper.writeValueAsString(website);
|
||||
System.out.println("CmsWebsite序列化结果: " + json);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TestObject {
|
||||
private String name;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime expirationTime;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user