Thymeleaf 常用代码
1、th:block:用于书写 thymeleaf 语法关键字,比如和 th:if 结合使用
<th:block th:if="">
...<span th:text="${post}"></span>
</th:block>
2、th:fragment="post(post,is_index)":代码片段,模拟函数传参功能
<th:block th:fragment="post(post,is_index)">
...<span th:text="${post}"></span>
</th:block>
调用上面的代码片段,基本格式 ~{模板文件位置 :: 声明的函数(传递的参数)} ,代码片段是存放在模板文件中,一个文件可以存放多个 fragement
<th:block th:replace="~{_macro/post :: post(post = ${post},is_index = 0)}"></th:block>
如果传递的参数仍然是一个代码片段,基本格式 ~{模板文件位置 :: 声明的函数(参数名=~{::代码片段})}
<th:block th:replace="~{_macro/post :: post(post = ~{::content})}">
<th:block th:fragment="content">
</th:block>
</th:block>
</th:block>
3、常用逻辑和运算符号
gt > lt < ge >= le <= not ! eq == neq ne !=