Thymeleaf是一个用于生成HTML页面的模板引擎,可以方便地实现页面跳转。
如果你想要在一个Thymeleaf页面中创建一个跳转按钮,可以使用以下代码:
<a th:href="@{/anotherPage}">Go to another page</a>
其中,th:href
是Thymeleaf的一个指令,用于设置链接的目标地址。@{/anotherPage}
表示要跳转到另一个页面,该页面的路径为/anotherPage
。
如果你想要创建一个按钮,可以将上述代码放入一个button
元素中:
<button th:onclick="location.href='@{/anotherPage}'">Go to another page</button>
其中,th:onclick
是Thymeleaf的一个指令,用于设置按钮的点击事件处理函数。location.href='@{/anotherPage}'
表示在点击该按钮后,将页面跳转到/anotherPage
。