一、引入依赖

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>

二、动态资源地位以及优先级

1.地位

  • static目录:css、js、图片等
  • templates目录:html页面(templates目录下的html页面不能间接拜访,须要通过服务器外部进行拜访,能够防止无权限的用户间接拜访到隐衷页面,造成信息泄露)

2.优先级

spring boot默认将/**动态资源拜访映射到以下目录:

classpath:/static
classpath:/public
classpath:/resources
classpath:/META-INF/resources

这四个目录的拜访优先级:META-INF/resources > resources > static > public
拜访门路与springboot.mvc.static-path-pattern、templates下文件夹等无关

三、编写Controller
1.应用@Controller,不能应用@RestController

因为@RestController返回的是@ResponseBody的json数据,且不走SpringMVC的视图解析流程,所以跳不到html那里

四、前端打包资源重定向
应用vue等框架打包的单页面资源,能够应用相似{module}-web的拜访门路,并且在controller中应用通配门路{modele}-web/**指向index.html。