Thymeleaf语法嵌套解决方法
Description:在写页面时常常会遇见thymeleaf语法中嵌套其他的thymeleaf,这时常见的处理方法有两种
eg:
若想要表达以下内容
<a th:if="${page.hasNextPage}" th:href="@{/employee/page/${page.pages}}">末页</a>
则有以下两种方式解决语法嵌套问题
- 字符串拼接
<a th:if="${page.hasNextPage}" th:href="@{'/employee/page/'+${page.pages}}">末页</a>
- 采用thymeleaf提供的简洁处理办法
即采用"||",这里有thymeleaf常见的语法介绍
<a th:if="${page.hasNextPage}" th:href="@{|/employee/page/${page.pages}|}">末页1</a>
以上两种解决办法的效果等价