首页 > 解决方案 > ThymLeaf:使用 th:{attribute} 设置现有属性

问题描述

在“为特定属性设置值”的ThymeLeaf 教程href中,他们都定义了属性并使用th:href.

取自文本的示例片段

<li><a href="product/list.html" th:href="@{/product/list}">Product List</a></li>

是否有理由包含href标签,因为它无论如何都会被设置?如果有人想要页面的静态视图(即没有渲染器),他们是否设置了这些值?

标签: javathymeleaf

解决方案


如果您的问题是如何使用 href 添加 attr :

<li>
  <a href="product/list.html" th:href="@{product/list(attrName=${attrValue})}"> 
      Product List 
  </a>
</li>

如果您的问题是如何重定向到静态页面:

// *** link to another page ***
<a th:href="@{staticPage}"> static page</a>

// *** Spring boot Controller ***
@RequestMapping(value="/staticPage", method=RequestMethod.GET)
public String staticPage(Model model) {
   return "staticPage";
}


推荐阅读