一:配置application.yml
有关thymeleaf中的默认配置可以去下面查看:org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties这个类的属性
二:添加Maven依赖
但几次都没有正确加载thymeleaf相关的jar,启动后无法访问,报404错误
最后反复修改org\springframework\boot\spring-boot-dependencies\2.0.0.M7\spring-boot-dependencies-2.0.0.M7.pom中spring-boot-starter-thymeleaf版本
改成1.5.9RELEASE和1.5.8RELEASE,最后在又改成2.0.0.M7,最终检查发现
org\springframework\boot\spring-boot-starter-thymeleaf\2.0.0.M7下有jar包了
三:建立thymeleaf模文件
四:controller映射模板文件
五:访问
${ProjectContextPath}/usethymeleaf
六:另注意点
1)spring-boot项目静态文件目录:/src/java/resources/static
2)spring-boot项目模板文件目录:/src/java/resources/templates
3)spring-boot静态首页的支持,即index.html放在以下目录结构会直接映射到应用的根目录下
classpath:/META-INF/resources/index.html
classpath:/resources/index.html
classpath:/static/index.html
calsspath:/public/index.html
即在这同个目录下的index.html会作为应用程序的默认首页引擎: