一、在配置文件中直接定义
在 application.properties 中直接定义过滤规则
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
二、在Java中直接定义
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// TODO Auto-generated method stub
WebMvcConfigurer.super.addResourceHandlers(registry);
registry.addResourceHandler("/static/**");
registry.addResourceHandler("classpath:/static/");
}