application.properties
# upload-path文件存放路径 root-path静态资源访问前缀 # upload-path + 各模块文件夹路径组成保存文件的全路径 # root-path + 各模块文件夹路径组成数据库保存的路径 web.upload-path=E:/uploadFiles/ web.root-path=/upload/ wxAvatar.upload-path=wxAvatar/ companyLogo.upload-path=companyLogo/
@Configuration
public class WebConfigurer implements WebMvcConfigurer{
private Logger logger = LoggerFactory.getLogger(WebConfigurer.class);
@Value("${web.upload-path}")
private String fileUploadPath;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")
.excludePathPatterns("/login")
.excludePathPatterns("/dologin")
.excludePathPatterns("/error")
.excludePathPatterns("/static/**");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//配置静态资源访问前缀
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/upload/**").addResourceLocations("file:/"+fileUploadPath);
}
}