springboot静态资源路径配置

自定义网页路径

1、在文件夹中定义
例如:
webpage 是在res资源文件夹下建的文件夹 里面放的是网页 网页是aa.html
在application.properties 文件中写

spring.resources.static-locations= classpath:/webpage/           //这里是文件存放的真实路径         
spring.mvc.static-path-pattern=/jjs/**                                             //这里是网页访问路径,jjs是随意写的

这样在访问 路径为 http://localhost:8080/jjs/aa.html 需要把jjs写上。
在application.yml中

spring:
  resources:
    static-locations: classpath:/wangye/
  mvc:
    static-path-pattern: /jjs/**

也可以直接写spring.resources.static-locations= classpath:/find_webpage/ 只写这一句
这样访问时 就直接 访问http://localhost:8080/aa.html 不需要加别的
2、在类中定义

 @Configuration
 public class MyImageAddr implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    
        registry.addResourceHandler("/jjs/**") //这是是访问路径,可以修改为其他的字符串
                	.addResourceLocations("classpath:/page/"); 这是放网页的路径 ,就是实际路径
                	
        registry.addResourceHandler("/js/**")
                .addResourceLocations("classpath:/js/");//实际路径

        registry.addResourceHandler("/css/**")
                .addResourceLocations("classpath:/css/");//实际路径

        registry.addResourceHandler("/fonts/**")
                .addResourceLocations("classpath:/fonts/");//实际路径
    }
 }

分别对应路径springboot静态资源路径配置