url映射:
代码如下:
"/upload/**"为映射路径,"file:D://upload/"为文件实际保存的本地路径
package cn.bgi.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer{
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/upload/**").addResourceLocations("file:D://upload/");
}
}
访问图片的url路径形式为:http://localhost:8070/upload/xxx.jpg