From a60661ed1cc3d83c89c3ee80d5277c239f40875c Mon Sep 17 00:00:00 2001 From: zhengjie <201507802@qq.com> Date: Sat, 12 Dec 2020 21:25:44 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2.6)?= =?UTF-8?q?=EF=BC=9Abug=E4=BF=AE=E5=A4=8D=EF=BC=8C=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E5=90=8E=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close https://github.com/elunez/eladmin/issues/514 --- .../me/zhengjie/config/ConfigurerAdapter.java | 35 +++++++++++++++++++ .../template/generator/front/index.ftl | 8 +---- 2 files changed, 36 insertions(+), 7 deletions(-) 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 962a9932..3f9a98ed 100644 --- a/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java +++ b/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java @@ -15,8 +15,13 @@ */ package me.zhengjie.config; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.alibaba.fastjson.support.config.FastJsonConfig; +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @@ -24,6 +29,11 @@ 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.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + /** * WebMvcConfigurer * @@ -62,4 +72,29 @@ public class ConfigurerAdapter implements WebMvcConfigurer { registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0); registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0); } + + @Override + public void configureMessageConverters(List> converters) { + FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); + List supportMediaTypeList = new ArrayList<>(); + supportMediaTypeList.add(MediaType.APPLICATION_JSON_UTF8); + FastJsonConfig config = new FastJsonConfig(); + config.setDateFormat("yyyy-MM-dd HH:mm:ss"); + config.setSerializerFeatures( + SerializerFeature.DisableCircularReferenceDetect, + //保留空的字段 + SerializerFeature.WriteMapNullValue, + //String null -> "" + SerializerFeature.WriteNullStringAsEmpty, + //Number null -> 0 + SerializerFeature.WriteNullNumberAsZero, + //List null-> [] + SerializerFeature.WriteNullListAsEmpty, + //Boolean null -> false + SerializerFeature.WriteNullBooleanAsFalse); + converter.setFastJsonConfig(config); + converter.setSupportedMediaTypes(supportMediaTypeList); + converter.setDefaultCharset(StandardCharsets.UTF_8); + converters.add(converter); + } } diff --git a/eladmin-system/src/main/resources/template/generator/front/index.ftl b/eladmin-system/src/main/resources/template/generator/front/index.ftl index f16209f2..0041afeb 100644 --- a/eladmin-system/src/main/resources/template/generator/front/index.ftl +++ b/eladmin-system/src/main/resources/template/generator/front/index.ftl @@ -85,14 +85,8 @@ {{ dict.label.${column.dictName}[scope.row.${column.changeColumnName}] }} - <#elseif column.columnType != 'Timestamp'> - <#else> - - - +