在 ThymeLeaf Tutorial对于“设置特定属性的值”,它们都定义了 href
属性并使用 th:href
设置它。
取自文本的示例片段
<li><a href="product/list.html" th:href="@{/product/list}">Product List</a></li>
是否有理由包含 href
标记,因为它无论如何都会被设置?他们是否设置这些值以防有人想要页面的静态 View ,即没有渲染器?
最佳答案
如果您问题是如何使用 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";
}
关于java - ThymeLeaf:使用 th:{attribute} 设置现有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51567101/