Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用thymeleaf迭代二维数组_Java_Spring_Thymeleaf - Fatal编程技术网

Java 如何使用thymeleaf迭代二维数组

Java 如何使用thymeleaf迭代二维数组,java,spring,thymeleaf,Java,Spring,Thymeleaf,我有一个数独生成器类,它以双数组int的形式返回一个9x9数独板,我试图循环遍历数组并创建一个表,但我被卡住了,在Thymeleaf网站上找不到任何信息 更新 多亏了@Nikolas,它才开始工作 <form id="sudokuBoard" method="post"> <table class="table table-dark"> <tr th:each="row: ${board}">

我有一个数独生成器类,它以双数组int的形式返回一个9x9数独板,我试图循环遍历数组并创建一个表,但我被卡住了,在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>
使用两个嵌套的th:each命令:

<table>
    <tr th:each="i: ${array}">
        <td th:each="item: ${j}">
            <span th:text="${item}"></span >
        </td>
    <tr>
</table>
使用两个嵌套的th:each命令:

<table>
    <tr th:each="i: ${array}">
        <td th:each="item: ${j}">
            <span th:text="${item}"></span >
        </td>
    <tr>
</table>

可以将二维阵列转换为单个阵列,如下所示:

int k = 0;

for (int i = 0; i < 3; i++)
{
   for (int j = 0; j < 3; j++)
   {
      single_array[k++] = twoD_array[i][j];
   }
}

可以将二维阵列转换为单个阵列,如下所示:

int k = 0;

for (int i = 0; i < 3; i++)
{
   for (int j = 0; j < 3; j++)
   {
      single_array[k++] = twoD_array[i][j];
   }
}

你能给我一些密码吗?要查看2d数组是如何编写的?这怎么太宽了?想详细说明一下吗?你能给出一些代码吗?要查看2d数组是如何编写的?这怎么太宽了?想详细说明一下吗?