¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.config; |
| | | |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.alibaba.fastjson.support.config.FastJsonConfig; |
| | | import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; |
| | | import com.lf.server.interceptor.AuthInterceptor; |
| | | import com.lf.server.service.all.SysService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.converter.HttpMessageConverter; |
| | | import org.springframework.util.AntPathMatcher; |
| | | import org.springframework.web.servlet.config.annotation.*; |
| | | |
| | | import java.nio.charset.Charset; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * Webé
置类 |
| | | * @author WWW |
| | | */ |
| | | @Configuration |
| | | public class WebConfig extends WebMvcConfigurationSupport { |
| | | @Autowired |
| | | private SysService sysService; |
| | | |
| | | /** |
| | | * è·åæ¦æªå¨å¯¹è±¡ |
| | | * |
| | | * @return |
| | | */ |
| | | public AuthInterceptor getAuthBean() { |
| | | return new AuthInterceptor(sysService); |
| | | } |
| | | |
| | | /** |
| | | * swaggeræ§å¶ |
| | | */ |
| | | @Override |
| | | protected void addResourceHandlers(ResourceHandlerRegistry registry) { |
| | | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); |
| | | registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); |
| | | registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); |
| | | super.addResourceHandlers(registry); |
| | | } |
| | | |
| | | /** |
| | | * 忽ç¥urlå°å大å°å |
| | | */ |
| | | @Override |
| | | protected void configurePathMatch(PathMatchConfigurer configurer) { |
| | | AntPathMatcher matcher = new AntPathMatcher(); |
| | | matcher.setCaseSensitive(false); |
| | | |
| | | configurer.setPathMatcher(matcher); |
| | | } |
| | | |
| | | /** |
| | | * è·¨åè¯·æ± |
| | | */ |
| | | @Override |
| | | protected void addCorsMappings(CorsRegistry registry) { |
| | | registry.addMapping("/**") |
| | | .allowCredentials(true) |
| | | .allowedOrigins("*") |
| | | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") |
| | | .allowedHeaders("*") |
| | | .maxAge(3600); |
| | | } |
| | | |
| | | /** |
| | | * æ·»å ç»ä¸çæ¦æªå¨ |
| | | */ |
| | | @Override |
| | | protected void addInterceptors(InterceptorRegistry registry) { |
| | | registry.addInterceptor(getAuthBean()) |
| | | // .excludePathPatterns("/swagger", "/webjars/**", "/v2/**", "/sign/**") |
| | | .addPathPatterns("/**"); |
| | | super.addInterceptors(registry); |
| | | } |
| | | |
| | | /** |
| | | * å¤çjsonæ ¼å¼ï¼å¼nullç转æ¢ä¸º"" |
| | | */ |
| | | @Override |
| | | public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
| | | FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); |
| | | FastJsonConfig config = new FastJsonConfig(); |
| | | config.setSerializerFeatures( |
| | | SerializerFeature.WriteNullListAsEmpty, |
| | | SerializerFeature.WriteMapNullValue, |
| | | //SerializerFeature.WriteNullStringAsEmpty, |
| | | SerializerFeature.WriteNullNumberAsZero, |
| | | SerializerFeature.WriteNullBooleanAsFalse); |
| | | // ç»ææ¯å¦æ ¼å¼å,é»è®¤ä¸ºfalse |
| | | //SerializerFeature.PrettyFormat); |
| | | |
| | | converter.setFastJsonConfig(config); |
| | | converter.setDefaultCharset(Charset.forName("UTF-8")); |
| | | converters.add(converter); |
| | | } |
| | | } |