thyemleaf
导入依赖
<!--thymeleaf模板-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
将html页面放在templates下就可。html需要导入thyemleaf约束
<html lang="en" xmlns:th="http://www.thymeleaf.org">
建议在使用thymeleaf时关闭缓存,否则会产生很大开销
spring.thymeleaf.cache=false
#thymeleaf是一个模板引擎,缓存的意思是加载一次模板之后便不会在加载了,对于生产环境应该加上缓存,但是在开发过程中如果打开缓存,不方便开发人员调试。试想一下,改一行html,就需要重启服务器,肯定是不方便的。
#总结一下:
#本地开发环境下,需要把缓存关闭,否则调试成本太大。其他环境下缓存都需要打开。
详细语法看在线文档
- thyemleaf在线文档:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
- Thymeleaf在Github的主页:https://github.com/thymeleaf/thymeleaf