源码地址:https://github.com/crayon-shin-chan/spring-boot-demo
1.SpringBoot配置文件
spring:
mvc:
static-path-pattern: /**
resources:
static-locations: classpath:/static
第一个指定的static-path-pattern为访问静态资源的路径,这个只能配置一个
第二个static-locations指定静态资源在服务器上的位置
classpath:开头的指的是类路径上的资源,一般指的是放在resources下的静态资源
file:开头的指的是文件系统的资源,后面跟外部文件目录
可见这种方式只能配置一个访问路径,如果需要配置多个不同的静态资源使用不同的访问路径,则这样做不到
2.Spring WebMvcConfigurer
public class SpringMvcConfig implements WebMvcConfigurer {
/**
* 静态资源配置,这里有两个路径:
* 1.addResourceHandler方法添加的路径