org.springframework.boot spring-boot-starter-thymeleaf
3.0.2.RELEASE 2.1.1
- springboot自带的thymeleaf依赖为2.1.3版本,使用thymeleaf-layout-dialect版本为2以下版本。
- 使用3或3以上的thymeleaf时,需要thymeleaf-layout-dialect的版本为2或以上。
- 锁定thymeleaf版本时不能使用thymeleaf.version标签,会和springboot内部的依赖标签冲突。应当使用springboot-thymeleaf.version标签来锁定版本。
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode=HTML
spring.thymeleaf.cache=false
spring.thymeleaf.cache为缓存,需要热部署时,需要设置为false
显示欢迎
显示欢迎
显示欢迎
访问属性域
访问请求域 方式一
访问请求域 方式二
访问Session域
访Session域 方式一
访问Application域 方式一
解析URL地址,获取ContextPath的值
@{}是把ContextPath的值附加到指定的地址前
@{}是把ContextPath的值附加到指定的地址前
直接执行表达式
无转义效果 : [[${attrRequestScope}]]
有转义效果 : [(${attrRequestScope})]
if判断字符串是否为空
attrRequestScope不为空显示
~~~attrRequestScope为空显示
~~~~
测试循环
- 使用th:each进行集合数据迭代
- th:each=“声明变量:${集合}”
- th:each 用在哪个标签上,哪个标签就会出现多次
要被引入的代码 include/part.html
被包含的内容1111
被包含的内容2222
被包含的内容3333
需要引入的页面
渲染后的页面源码
被包含的内容1111
被包含的内容2222
被包含的内容3333
- " :: "左边的值拼前后缀后必须能够找到要包含的文件。
- " :: " 右边的值是代码片段的名字 ,就是th:fragment的值。
- insert将代码原样引入。
- replace使用被引入的代码和属性替换原有的。
- include使用被引入的代码div内部的代码。