我有一个sudoku生成器类,它作为一个双数组(int)返回一个9x9 sudoku板,我试图遍历这个数组并创建一个表,但是我被困住了,在Thymeleaf网站上找不到任何信息。
更新
多亏了@Nikolas
<form id="sudokuBoard" method="post">
<table class="table table-dark">
<tr th:each="row: ${board}">
<td th:each="value: ${row}">
<div th:switch="${value}">
<input th:case="0" style="width:30px;height:30px;text-align:center" type = "text" maxlength="1" value="0">
<input th:case="*" style="width:30px;height:30px;text-align:center;background-color:lightgreen" type = "text" th:value="${value}" readonly>
</div>
</td>
</tr>
</table>
<input type="submit"> Check Solution </input>
</form>发布于 2019-05-06 11:26:19
使用2个嵌套的th:each命令:
<table>
<tr th:each="i: ${array}">
<td th:each="item: ${j}">
<span th:text="${item}"></span >
</td>
<tr>
</table>发布于 2019-05-06 11:27:04
您可以将2d数组转换为如下所示的单个数组:
int k = 0;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
single_array[k++] = twoD_array[i][j];
}
}https://stackoverflow.com/questions/56004086
复制相似问题