|
|
@@ -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); |
|
|
|