feat(base): 为 BaseEntity 添加序列化接口并配置 Jackson 时间和 Long 类型处理
- 为 BaseEntity 类实现 Serializable 接口以支持序列化 - 新增 JacksonConfig 配置类处理时间格式和 Long 类型精度问题 - 配置时区为 Asia/Shanghai 和中国地区格式 - 添加 Long 类型的序列化和反序列化器避免前端精度丢失 - 将项目版本从 1.5.3 升级到 1.5.4
This commit is contained in:
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.4</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>ZKH Framework</name>
|
<name>ZKH Framework</name>
|
||||||
<description>A Java framework for ZKH applications</description>
|
<description>A Java framework for ZKH applications</description>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-common</artifactId>
|
<artifactId>zkh-common</artifactId>
|
||||||
|
|||||||
@ -8,72 +8,73 @@ import org.springframework.data.annotation.LastModifiedBy;
|
|||||||
import org.springframework.data.annotation.LastModifiedDate;
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class BaseEntity {
|
public class BaseEntity implements Serializable {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@CreatedDate
|
@CreatedDate
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@LastModifiedDate
|
@LastModifiedDate
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private LocalDateTime updateTime;
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@CreatedBy
|
@CreatedBy
|
||||||
private String createBy;
|
private String createBy;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
@LastModifiedBy
|
@LastModifiedBy
|
||||||
private String updateBy;
|
private String updateBy;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getCreateTime() {
|
public LocalDateTime getCreateTime() {
|
||||||
return createTime;
|
return createTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreateTime(LocalDateTime createTime) {
|
public void setCreateTime(LocalDateTime createTime) {
|
||||||
this.createTime = createTime;
|
this.createTime = createTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getUpdateTime() {
|
public LocalDateTime getUpdateTime() {
|
||||||
return updateTime;
|
return updateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdateTime(LocalDateTime updateTime) {
|
public void setUpdateTime(LocalDateTime updateTime) {
|
||||||
this.updateTime = updateTime;
|
this.updateTime = updateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreateBy() {
|
public String getCreateBy() {
|
||||||
return createBy;
|
return createBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreateBy(String createBy) {
|
public void setCreateBy(String createBy) {
|
||||||
this.createBy = createBy;
|
this.createBy = createBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUpdateBy() {
|
public String getUpdateBy() {
|
||||||
return updateBy;
|
return updateBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdateBy(String updateBy) {
|
public void setUpdateBy(String updateBy) {
|
||||||
this.updateBy = updateBy;
|
this.updateBy = updateBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-data</artifactId>
|
<artifactId>zkh-data</artifactId>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-file</artifactId>
|
<artifactId>zkh-file</artifactId>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-log</artifactId>
|
<artifactId>zkh-log</artifactId>
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>vip.jcfd</groupId>
|
<groupId>vip.jcfd</groupId>
|
||||||
<artifactId>zkh-framework</artifactId>
|
<artifactId>zkh-framework</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.4</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>zkh-web</artifactId>
|
<artifactId>zkh-web</artifactId>
|
||||||
|
|||||||
56
zkh-web/src/main/java/vip/jcfd/web/config/JacksonConfig.java
Normal file
56
zkh-web/src/main/java/vip/jcfd/web/config/JacksonConfig.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package vip.jcfd.web.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class JacksonConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures Jackson mapper with locale, timezone, date format, serializer
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
||||||
|
return jacksonObjectMapperBuilder -> {
|
||||||
|
jacksonObjectMapperBuilder.locale(Locale.CHINA);
|
||||||
|
jacksonObjectMapperBuilder.timeZone(TimeZone.getTimeZone(ZoneId.of("Asia/Shanghai")));
|
||||||
|
jacksonObjectMapperBuilder.simpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
jacksonObjectMapperBuilder.serializers(new LongSerializer());
|
||||||
|
jacksonObjectMapperBuilder.deserializers(new LongDeserializer());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LongSerializer extends JsonSerializer<Long> {
|
||||||
|
@Override
|
||||||
|
public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||||
|
if (value == null) {
|
||||||
|
gen.writeNull();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gen.writeString(String.valueOf(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class LongDeserializer extends JsonDeserializer<Long> {
|
||||||
|
@Override
|
||||||
|
public Long deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||||
|
if (p.getText() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Long.parseLong(p.getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user