kongzy
2024-06-03 022b17044ab6bb284fd6313da91d1d1dfb2d5079
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.gkhy.assess.framework.config;
 
import com.gkhy.assess.framework.interceptor.LogInterceptor;
import com.gkhy.assess.framework.interceptor.RepeatSubmitInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
import java.io.File;
 
 
@Configuration
// 指定要扫描的Mapper类的包的路径
@MapperScan("com.gkhy.**.mapper")
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Value("${image.upload_path}")
    private String uploadPath;
 
    @Autowired
    private LogInterceptor logInterceptor;
 
    @Autowired
    private RepeatSubmitInterceptor repeatSubmitInterceptor;
 
    /**
     * 配置图片访问路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String systemDir=System.getProperty("user.dir");
        registry.addResourceHandler("/upload/**").addResourceLocations("file:"+systemDir+ File.separator+uploadPath+File.separator);
      }
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInterceptor)
                .addPathPatterns("/**");
        registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
 
    }
 
}