设置静态资源的映射
1、當沒有設置靜態資源映射時,我們需要將靜態資源放在static下面。
訪問login.html的路徑是:http://localhost:8080/pages/login.html
訪問index.html的路徑是:http://localhost:8080/index.html
?
2、當設置靜態資源訪問時,靜態資源可以直接放在resources下面
訪問login.html的路徑是:http://localhost:8080/pages/login.html
?
import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;//靜態資源訪問配置 @Configuration public class WebMvcConfig extends WebMvcConfigurationSupport {@Overrideprotected void addResourceHandlers(ResourceHandlerRegistry registry) {//路徑中帶有/pages/** 會映射到類路徑下的(也就是resources下) /pages/registry.addResourceHandler("/pages/**").addResourceLocations("classpath:/pages/");} }總結
- 上一篇: 图扑软件数字孪生 | 基于 BIM 技术
- 下一篇: java开发面试 自我介绍 与 项目介