SpringBoot处理静态资源的两种方式

静态资源是指----》 CSS、JS之类的文件

首先创建SpringBoot Web项目

添加Spring Boot Web Starter

1         <dependency>
2             <groupId>org.springframework.boot</groupId>
3             <artifactId>spring-boot-starter-web</artifactId>
4         </dependency>

第一种方式(将静态资源文件放至静态资源文件夹)

  ① “/”  当前项目的根路径

  ②classpath:/META-INF/resources/  

  ③classpath:/resources/

  ④classpath:/static/

  ⑤classpath:/public/

* 项目的欢迎页会在上面的5个地址寻找index.html

* 项目的页面图标会在上面的5个地址寻找favicon.ico

* 可以通过配置文件来覆盖默认的静态资源文件夹地址

  

1 spring.resources.static-locations=classpath:/coreqi/

第二种方式(使用webjars)

webjars是一种以jar包方式引入静态资源

https://www.webjars.org/

所有的/webjars/**请求都将去classpath:/META-INF/resources/webjars/去寻找资源

例如:

  

1         <dependency>
2             <groupId>org.webjars</groupId>
3             <artifactId>jquery</artifactId>
4             <version>3.3.1-1</version>
5         </dependency>

猜你喜欢

转载自www.cnblogs.com/fanqisoft/p/10323117.html