在@EnableWebMvc注解并且继承WebMvcConfigurerAdapter类的配置中重写addResourceHandlers方法:
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//静态文件存放路径
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
}