月球大数据地理空间分析展示平台-【后端】-月球后台服务
1
13693261870
2024-11-11 fee67ca8a0760315047a52fc4101a8f4f80b7a7f
src/main/java/com/moon/server/config/WebConfig.java
@@ -13,37 +13,25 @@
import org.springframework.web.servlet.config.annotation.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
 * Web配置类
 * @author WWW
 */
@Configuration
@SuppressWarnings("ALL")
public class WebConfig extends WebMvcConfigurationSupport {
    @Autowired
    private SysService sysService;
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 设置访问路径为 “/” 跳转到指定页面
        registry.addViewController("/").setViewName("redirect:/sign/toIndex");
        // 设置为最高优先级
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
    /**
     * 获取拦截器对象
     *
     * @return
     */
    public AuthInterceptor getAuthBean() {
        return new AuthInterceptor(sysService);
    }
    /**
     * swagger控制
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
@@ -52,9 +40,6 @@
        super.addResourceHandlers(registry);
    }
    /**
     * 忽略url地址大小写
     */
    @Override
    protected void configurePathMatch(PathMatchConfigurer configurer) {
        AntPathMatcher matcher = new AntPathMatcher();
@@ -63,9 +48,6 @@
        configurer.setPathMatcher(matcher);
    }
    /**
     * 跨域请求
     */
    @Override
    protected void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
@@ -76,9 +58,6 @@
                .maxAge(3600);
    }
    /**
     * 添加统一的拦截器
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAuthBean())
@@ -87,9 +66,6 @@
        super.addInterceptors(registry);
    }
    /**
     * 处理json格式,值null的转换为""
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
@@ -100,11 +76,10 @@
                //SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteNullBooleanAsFalse);
        // 结果是否格式化,默认为false
        //SerializerFeature.PrettyFormat);
        converter.setFastJsonConfig(config);
        converter.setDefaultCharset(Charset.forName("UTF-8"));
        converter.setDefaultCharset(StandardCharsets.UTF_8);
        converters.add(converter);
    }
}