# SpringBoot 配置静态资源文件映射
# 配置文件映射为项目路径下
# .properties 文件配置方式
spring.mvc.static-path-pattern=/static/images/**
spring.web.resources.static-locations=classpath:/static
图例:
# java 代码配置方式
package org.example.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @ClassName WebConfig
* @Description TODO
* @Date 2023/2/28
**/
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/images/**").addResourceLocations("classpath:" + "/static");
}
}
# 配置