首页>代码>springboot仿百度网盘开发的在线云盘项目>/CJPan/src/main/java/com/whut/pan/config/WebMvcConfiguration.java
package com.whut.pan.config;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * Web配置
 *
 * @author Sandeepin
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${fileRootPath}")
    private String fileRootPath;

    /**
     * 配置静态访问资源
     *
     * @param registry 注册
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        logger.warn("addResourceHandlers() fileRootPath:{}", fileRootPath);
        // Spring Boot 2 需要自己添加static文件夹
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/data/**").addResourceLocations("file:" + fileRootPath);
    }

    /**
     * 跳转页面
     *
     * @param registry 注册
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/toLogin").setViewName("login");
    }

    /**
     * 拦截器
     *
     * @param registry 拦截器注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则,excludePathPatterns 用户排除拦截,Spring Boot 2 需要自己添加static文件夹
        registry.addInterceptor(new WebInterceptor())
            .excludePathPatterns(
                Arrays.asList("/static/**", "/toLogin", "/login", "/deleteUser", "/alterPassword", "/signin", "/data",
                    "/test", "/upload", "/test1", "/shareCallBack", "/share", "/sharefile", "/sharefileSecret",
                    "/test2", "/errorPage", "/shareToMyPan", "/downloadApk", "/onlineplayer"));
    }

    /**
     * 配置fastJson
     *
     * @param converters converters
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
        fastConverter.setFastJsonConfig(fastJsonConfig);
        converters.add(fastConverter);
    }

}
最近下载更多
francochan  LV6 2024年5月4日
kkkllll  LV2 2024年1月26日
shuangfu  LV25 2023年10月19日
molu123456 2023年10月10日
暂无贡献等级
thsgli  LV9 2023年3月14日
MAOMAO999999  LV4 2023年3月4日
xxn1234567  LV1 2023年2月1日
cxz2132132  LV11 2022年11月18日
qlpqlp  LV7 2022年11月14日
huyuxin  LV4 2022年11月9日
最近浏览更多
yimaoermao  LV1 2024年11月28日
Boss绝  LV10 2024年11月12日
charleswang  LV7 2024年10月21日
grant1123  LV2 2024年6月22日
TY0165  LV20 2024年6月21日
17380184110 2024年6月19日
暂无贡献等级
来一杯西瓜冰咩  LV6 2024年5月13日
xiaozhi丶  LV15 2024年3月24日
暂无贡献等级
wyyz5211314  LV4 2024年1月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友