From 20ac35008c7c5eb6e9fbd13695364671e929bf25 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Wed, 21 Aug 2024 16:33:39 +0800 Subject: [PATCH] =?UTF-8?q?modify:=201.=20=E9=87=91=E9=A2=9D=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=B8=BA=E5=9B=9B=E8=88=8D?= =?UTF-8?q?=E4=BA=94=E5=85=A5=E4=B8=A4=E4=BD=8D=E5=B0=8F=E6=95=B0=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hz/pm/api/common/config/ConfigurerAdapter.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/common/config/ConfigurerAdapter.java b/hz-pm-api/src/main/java/com/hz/pm/api/common/config/ConfigurerAdapter.java index 8746812..0c6ca62 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/common/config/ConfigurerAdapter.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/common/config/ConfigurerAdapter.java @@ -1,6 +1,7 @@ package com.hz.pm.api.common.config; import com.alibaba.fastjson.serializer.SerializerFeature; +import com.alibaba.fastjson.serializer.ValueFilter; import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import com.hz.pm.api.common.interceptor.LogInterceptor; @@ -12,6 +13,8 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -32,6 +35,13 @@ public class ConfigurerAdapter implements WebMvcConfigurer { FastJsonConfig config = new FastJsonConfig(); config.setDateFormat("yyyy-MM-dd HH:mm:ss"); config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); + config.getSerializeConfig().addFilter(BigDecimal.class, (ValueFilter) (object, name, value) -> { + if (!(value instanceof BigDecimal)) { + return value; + } + // 保留两位小数 + return ((BigDecimal) value).setScale(2, RoundingMode.HALF_UP).toPlainString(); + }); converter.setFastJsonConfig(config); converter.setSupportedMediaTypes(supportMediaTypeList); converter.setDefaultCharset(StandardCharsets.UTF_8);