我是 thymeleaf 的新手,我正在尝试使用数组和 each 循环制作一个简单的表格。
我的代码是这样的:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Smoke Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<table border="1" style="width:300px">
<tr>
<td>Test Name</td>
</tr>
<tr th:each="smokeTest : ${smokeTests}">
<td>
th:text="${smokeTest.name}">A Smoke Test'
</td>
</tr>
</table>
</body>
</html>
基本上我的问题是我不能以 <td>
运行循环在 <tr>
内秒。有什么方法可以让这段代码起作用吗?
最佳答案
你必须把 th:text 作为一个标签的属性,所以
<tr th:each="smokeTest : ${smokeTests}">
<td th:text="${smokeTest.name}">A Smoke Test'</td>
</tr>
应该运行。
关于html - 在 thymeleaf 中创建一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24614113/