首页>代码>springboot仿百度网盘开发的在线云盘项目>/CJPan/src/main/java/com/whut/pan/config/WebMvcConfiguration.java
01package com.whut.pan.config;
02 
03import com.alibaba.fastjson.serializer.SerializerFeature;
04import com.alibaba.fastjson.support.config.FastJsonConfig;
05import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
06 
07import org.slf4j.Logger;
08import org.slf4j.LoggerFactory;
09import org.springframework.beans.factory.annotation.Value;
10import org.springframework.context.annotation.Configuration;
11import org.springframework.http.converter.HttpMessageConverter;
12import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
13import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
14import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
15import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
16 
17import java.util.Arrays;
18import java.util.List;
19 
20/**
21 * Web配置
22 *
23 * @author Sandeepin
24 */
25@Configuration
26public class WebMvcConfiguration implements WebMvcConfigurer {
27 
28    private Logger logger = LoggerFactory.getLogger(this.getClass());
29 
30    @Value("${fileRootPath}")
31    private String fileRootPath;
32 
33    /**
34     * 配置静态访问资源
35     *
36     * @param registry 注册
37     */
38    @Override
39    public void addResourceHandlers(ResourceHandlerRegistry registry) {
40        logger.warn("addResourceHandlers() fileRootPath:{}", fileRootPath);
41        // Spring Boot 2 需要自己添加static文件夹
42        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
43        registry.addResourceHandler("/data/**").addResourceLocations("file:" + fileRootPath);
44    }
45 
46    /**
47     * 跳转页面
48     *
49     * @param registry 注册
50     */
51    @Override
52    public void addViewControllers(ViewControllerRegistry registry) {
53        registry.addViewController("/toLogin").setViewName("login");
54    }
55 
56    /**
57     * 拦截器
58     *
59     * @param registry 拦截器注册
60     */
61    @Override
62    public void addInterceptors(InterceptorRegistry registry) {
63        // addPathPatterns 用于添加拦截规则,excludePathPatterns 用户排除拦截,Spring Boot 2 需要自己添加static文件夹
64        registry.addInterceptor(new WebInterceptor())
65            .excludePathPatterns(
66                Arrays.asList("/static/**", "/toLogin", "/login", "/deleteUser", "/alterPassword", "/signin", "/data",
67                    "/test", "/upload", "/test1", "/shareCallBack", "/share", "/sharefile", "/sharefileSecret",
68                    "/test2", "/errorPage", "/shareToMyPan", "/downloadApk", "/onlineplayer"));
69    }
70 
71    /**
72     * 配置fastJson
73     *
74     * @param converters converters
75     */
76    @Override
77    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
78        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
79        FastJsonConfig fastJsonConfig = new FastJsonConfig();
80        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
81        fastConverter.setFastJsonConfig(fastJsonConfig);
82        converters.add(fastConverter);
83    }
84 
85}
最近下载更多
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  LV3 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日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友