|
@@ -1,55 +1,23 @@ |
|
|
package com.hz.pm.api.common.config; |
|
|
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; |
|
|
import com.hz.pm.api.common.interceptor.LogInterceptor; |
|
|
|
|
|
import com.ningdatech.basic.config.BaseConfig; |
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
import org.springframework.context.annotation.Configuration; |
|
|
import org.springframework.context.annotation.Configuration; |
|
|
import org.springframework.http.MediaType; |
|
|
|
|
|
import org.springframework.http.converter.HttpMessageConverter; |
|
|
|
|
|
import org.springframework.lang.NonNull; |
|
|
import org.springframework.lang.NonNull; |
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc; |
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author qinxianyun |
|
|
* @author qinxianyun |
|
|
*/ |
|
|
*/ |
|
|
@EnableWebMvc |
|
|
|
|
|
@Configuration |
|
|
@Configuration |
|
|
public class ConfigurerAdapter implements WebMvcConfigurer { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
|
|
|
|
|
// 使用 fastjson 序列化,会导致 @JsonIgnore 失效,可以使用 @JSONField(serialize = false) 替换 |
|
|
|
|
|
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); |
|
|
|
|
|
List<MediaType> supportMediaTypeList = new ArrayList<>(); |
|
|
|
|
|
supportMediaTypeList.add(MediaType.APPLICATION_JSON); |
|
|
|
|
|
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); |
|
|
|
|
|
converters.add(converter); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
|
public class ConfigurerAdapter extends BaseConfig { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void addInterceptors(@NonNull InterceptorRegistry registry) { |
|
|
public void addInterceptors(@NonNull InterceptorRegistry registry) { |
|
|
registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**").order(-100); |
|
|
registry.addInterceptor(new LogInterceptor()).addPathPatterns("/**").order(-100); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |