如何加载静态图片
java工具类
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class ShowImage extends WebMvcConfigurerAdapter {
@Value("${upload.path.prefix}")
private String prefix;
@Value("${upload.path.res}")
private String uploadPath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//注:使用此种方法进行路径配置时,“file:D:/OTA/” 为正确路径地址 “file:D:/OTA”为错误路径地址,需以反斜杠结尾才可正确加载
registry.addResourceHandler("/images
@Configuration
public class UrlConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//addResourceHandler是指你想在url请求的路径
//addResourceLocations是图片存放的真实路径
registry.addResourceHandler("/image/**").addResourceLocations("file:D:\\file\\");
}
}
但是得在你的页面显示前面加上
例如:
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。