import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
/**
* 图片绝对地址与虚拟地址映射
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String os = System.getProperty("os.name");
if (os.toLowerCase().startsWith("win")) { //如果是Windows系统
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/public/")
.addResourceLocations("classpath:/static/")
.addResourceLocations("file:./WebRes/"); //媒体资源绝对路径
} else { //linux 和mac
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/public/")
.addResourceLocations("classpath:/static/**")
.addResourceLocations("file:./WebRes/");//媒体资源绝对路径
}
super.addResourceHandlers(registry);
}
//注册swagger
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedHeaders("*")
.allowCredentials(true)
.allowedMethods("*");
}
/* *
* @Author lsc
* 设置拦截路径
* @Param [registry]
* @Return void
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {
}
}
07-19
1757
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-18
395
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-21
98
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)