解决:实现WebMvcConfigurer配置接口的addResourceHandlers方法,为静态资源添加项目路径,解决404问题
// 需添加Configuration注解
package config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyInterceptorCfg implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/community/**").addResourceLocations("classpath:/community/");
}
}
//引用静态资源
<link rel="stylesheet" th:href="@{/css/global.css}" />
引用:
Spring Boot 配置接口 WebMvcConfigurer