1、目录
src/main/java :存放java代码
src/main/resources
static:存放静态文件,比如css、js、image(访问方式 http://localhost:8080/js/main.js)
templates:存放静态页面jsp,html,tpl
config:存放配置文件application.properties
resources:
2、静态文件加载顺序:Spring Boot默认依次从:META/resources > resources >static >public > 如果存在访问的资源则返回,否则报错!
3、引入依赖 Thymeleaf
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
新建controller映射过去,例如404错误页面
package cn.xiaobing.demo.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class FailController { @RequestMapping(value = "/v1/fail") public Object fail() { return "404"; } }
启动项目:
访问映射地址:
4、static:存放静态文件,比如css、js、image(访问方式 http://localhost:8080/image/500.png)
启动项目:
5、自定义路径访问如
新建配置文件:application.properties
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/testCustom/
启动项目:
. ____ _ __ _ _ /\ / ___'_ __ _ _(_)_ __ __ _ ( ( )\___ | '_ | '_| | '_ / _` | \/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE)
访问资源地址:
6、更多学习请spring官网查询
7、不足之处,后续补充!