Products
GG网络技术分享 2025-11-13 17:02 6
从您给的文本中, 我们Neng了解到关于Spring Boot中静态材料映射的几个关键点:
静态材料默认映射规则

自定义静态材料映射
properties
spring.resources.static-locations=classpath:/custom-static/
yaml
spring:
resources:
static-locations: classpath:/custom-static/
用WebMvcConfigurer接口
比方说: java 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 StaticResourceConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers { registry.addResourceHandler.addResourceLocations; } }
classpath:/custom/目录下的材料dou将映射到URL模式下的/custom/**。静态材料访问
localhost:8080/custom/resource.jpg来获取位于classpath:/custom/目录下的resource.jpg文件。Spring Boot与WebJars
通过以上信息, Spring Boot开发者Neng有效地管理和访问静态材料,从而搞优良Web应用程序的性Neng和用户体验。
Demand feedback