heheng
6 天以前 81791ded0d0bf0a452dcc3a96f25ea3bb12ebfcb
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
package com.gkhy.exam.framework.config;
 
import com.gkhy.exam.framework.interceptor.RepeatSubmitInterceptor;
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类的包的路径
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Value("${image.upload_image}")
    private String uploadPath;
 
    @Autowired
    private RepeatSubmitInterceptor repeatSubmitInterceptor;
 
    /**
     * 配置图片访问路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String systemDir=System.getProperty("user.dir");
        registry.addResourceHandler("/images/**").addResourceLocations("file:"+systemDir+ File.separator+uploadPath+File.separator);
      }
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
    }
 
}