WebConfig文件内容
package com.example.demo2.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//web项目配置类
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 映射轮播图的图片
registry.addResourceHandler("/image/swiper/**").addResourceLocations("file:E:\\demo2\\swiperImgs\\");
// 映射商品大类的图片
registry.addResourceHandler("/image/bigType/**").addResourceLocations("file:E:\\demo2\\bigTypeImgs\\");
// 映射热门商品的图片
registry.addResourceHandler("/image/hotProduct/**").addResourceLocations("file:E:\\demo2\\productImgs\\");
}
}
本地浏览器接口测试地址:
http://localhost:8089/image/swiper/1.jpg
本地文件存放路径:
E:\demo2\swiperImgs
注意在代码中一定要加\