|
@@ -2,16 +2,24 @@ package com.etotem.num.config;
|
|
|
|
|
|
|
|
import com.etotem.num.interceptor.AdminInterceptor;
|
|
import com.etotem.num.interceptor.AdminInterceptor;
|
|
|
import com.etotem.num.interceptor.AuthInterceptor;
|
|
import com.etotem.num.interceptor.AuthInterceptor;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
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 org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
|
+
|
|
|
@Configuration
|
|
@Configuration
|
|
|
public class WebMvcConfig implements WebMvcConfigurer {
|
|
public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
private final AuthInterceptor authInterceptor;
|
|
private final AuthInterceptor authInterceptor;
|
|
|
private final AdminInterceptor adminInterceptor;
|
|
private final AdminInterceptor adminInterceptor;
|
|
|
|
|
|
|
|
|
|
+ @Value("${app.upload.dir:./uploads}")
|
|
|
|
|
+ private String uploadDir;
|
|
|
|
|
+
|
|
|
public WebMvcConfig(AuthInterceptor authInterceptor, AdminInterceptor adminInterceptor) {
|
|
public WebMvcConfig(AuthInterceptor authInterceptor, AdminInterceptor adminInterceptor) {
|
|
|
this.authInterceptor = authInterceptor;
|
|
this.authInterceptor = authInterceptor;
|
|
|
this.adminInterceptor = adminInterceptor;
|
|
this.adminInterceptor = adminInterceptor;
|
|
@@ -26,4 +34,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
.addPathPatterns("/api/admin/**")
|
|
.addPathPatterns("/api/admin/**")
|
|
|
.excludePathPatterns("/api/admin/login");
|
|
.excludePathPatterns("/api/admin/login");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
|
|
|
+ Path absolutePath = Paths.get(uploadDir).toAbsolutePath().normalize();
|
|
|
|
|
+ registry.addResourceHandler("/uploads/**")
|
|
|
|
|
+ .addResourceLocations("file:" + absolutePath.toString() + "/");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|