@Configurationpublic class MyWebMvcConfigurer extends WebMvcConfigurationSupport {@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {// 访问相对路径registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets/");// 访问绝对路径 访问路径和 存放路径可以自定义,建议存放路径放到配置文件中registry.addResourceHandler("/img/**").addResourceLocations("file:D:/img/");super.addResourceHandlers(registry);}}
localhost:8080/assets/文件名.后缀
localhost:8080/img/文件名.后缀