第一种方案:
直接修改yml配置文件:
1 2 3 4 5 6 7 8 |
#thymeleaf thymeleaf: cache: false prefix: classpath:/templates/ check-template-location: true suffix: .html encoding: utf-8 mode: HTML |
#这个是关键,放开springboot对静态资源的拦截
mvc:
static-path-pattern: /static/**
第二种方案:
增加java类,告诉springboot对静态资源的加载路径
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * 配置静态资源映射 **/ @Component public class WebMvcConfig implements WebMvcConfigurer { /** * 添加静态资源文件,外部可以直接访问地址 * * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); //此处还可继续增加目录。。。。 } } |