From 8a88f90367f22dc645ec711ebe9bf089dd357240 Mon Sep 17 00:00:00 2001 From: zhengjie Date: Mon, 22 Apr 2019 15:53:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8System=E6=A8=A1=E5=9D=97=E7=9A=84Confi?= =?UTF-8?q?gurerAdapter=E7=B1=BB=E4=B8=AD=E6=B7=BB=E5=8A=A0=20=E8=A7=A3?= =?UTF-8?q?=E5=86=B3Long=20=E7=B1=BB=E5=9E=8B=E5=9C=A8=20=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=B2=BE=E5=BA=A6=E4=B8=A2=E5=A4=B1=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhengjie/config/ConfigurerAdapter.java | 28 +++++++++++++++++++ .../modules/system/service/dto/DictDTO.java | 1 - 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java b/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java index 848c527a..01df206a 100644 --- a/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java +++ b/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java @@ -1,10 +1,19 @@ package me.zhengjie.config; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.math.BigInteger; +import java.nio.charset.Charset; +import java.util.List; /** * WebMvcConfigurer @@ -26,6 +35,25 @@ public class ConfigurerAdapter implements WebMvcConfigurer { } +// 可解决Long 类型在 前端精度丢失的问题, 如不想全局 直接添加注解 @JsonSerialize(using= ToStringSerializer.class) 到相应的字段上 + +// @Override +// public void configureMessageConverters(List> converters) { +// +// MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = +// new MappingJackson2HttpMessageConverter(); +// +// ObjectMapper objectMapper = new ObjectMapper(); +// SimpleModule simpleModule = new SimpleModule(); +// simpleModule.addSerializer(BigInteger.class, ToStringSerializer.instance); +// simpleModule.addSerializer(Long.class, ToStringSerializer.instance); +// simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); +// objectMapper.registerModule(simpleModule); +// jackson2HttpMessageConverter.setObjectMapper(objectMapper); +// converters.add(jackson2HttpMessageConverter); +// converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8"))); +// } + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DictDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DictDTO.java index 623ac625..38f38596 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DictDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DictDTO.java @@ -1,7 +1,6 @@ package me.zhengjie.modules.system.service.dto; import lombok.Data; -import java.sql.Timestamp; import java.io.Serializable; /**