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表单从th:each列表中获取了错误的属性_Java_Spring_Thymeleaf - Fatal编程技术网

Java Thymeleaf表单从th:each列表中获取了错误的属性

Java Thymeleaf表单从th:each列表中获取了错误的属性,java,spring,thymeleaf,Java,Spring,Thymeleaf,我对${ad.id}属性有问题-每行都有一些id值。对于第一行,一切正常,但对于下一行,只有delete按钮发送正确的id值。当我点击编辑按钮(任意一行)并且模态表单弹出时,它得到第一行的id值。我不知道为什么会发生这种情况,我将感谢任何帮助 条纹行 .table striped类将斑马条纹添加到表格中: 身份证件 标题 编辑 删除 约翰 雌鹿 编辑 &时代; 编辑 标题: 正文: 提交 接近 保存更改 好吧,我想每个“模态”都有相同的myModal id,所以每次我单击编辑按钮时,它都会

我对${ad.id}属性有问题-每行都有一些id值。对于第一行,一切正常,但对于下一行,只有delete按钮发送正确的id值。当我点击编辑按钮(任意一行)并且模态表单弹出时,它得到第一行的id值。我不知道为什么会发生这种情况,我将感谢任何帮助


条纹行
.table striped类将斑马条纹添加到表格中:

身份证件 标题 编辑 删除 约翰 雌鹿 编辑 &时代; 编辑 标题: 正文: 提交 接近 保存更改

好吧,我想每个“模态”都有相同的myModal id,所以每次我单击编辑按钮时,它都会将第一个id的值作为第一个id为“myModal”的id。为了使它正常工作,我必须将data target=“#myModal”更改为th:attr=“data target=”#myModal'+${ad.id}”和id=“myModal”更改为th:id=“myModal+${ad.id}”我发现,每个“modal”都有相同的myModal id,所以每次单击编辑按钮时,它都会接受第一个id的值,因为它是第一个id为“myModal”的id。为了使其正常工作,我必须将data target=“#myModal”更改为th:attr=“data target=”#myModal'+${ad.id}”并将id=“myModal”更改为th:id=“myModal+${ad.id}”
<div class="container">
<h2>Striped Rows</h2>
<p>The .table-striped class adds zebra-stripes to a table:</p>
<table class="table table-striped">
    <thead>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Edit</th>
        <th>Delete</th>
    </tr>
    </thead>
    <tbody>
    <tr  th:each="ad : ${allads}">
        <td th:text="${ad.id}">John</td>
        <td th:text="${ad.name}">Doe</td>
        <td>

            <!--MODAL-->

            <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">
                edit
            </button>

            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">Edit</h4>
                        </div>
                        <div class="modal-body">

                            <!--FORM-->

                            <form class="form-horizontal" role="form" action="#"
                                  th:action="@{editAd}" th:object="${adEdit}" method="post">
                                <div class="form-group">
                                    <label class="control-label col-sm-2" for="title">Title:</label>
                                    <div class="col-sm-10" >
                                        <input type="text" th:field="*{name}"  class="form-control" id="title" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-sm-2" for="pwd">Text:</label>
                                    <div class="col-sm-10">
                                        <textarea id="pwd" th:field="*{text}" rows="10" cols="55" th:text="${ad.text}"></textarea>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <input type="hidden" th:value="${ad.id}" th:name="idEdit"/>
                                        <button type="submit" class="btn btn-default">Submit</button>
                                    </div>
                                </div>
                            </form>



                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            <button type="button" class="btn btn-primary">Save changes</button>
                        </div>
                    </div>
                </div>
            </div>


        </td>

        <!--DELETE-->

        <td>
            <form method="POST" action="#" th:action="@{deleteAd}">
                <input type="hidden" th:value="${ad.id}" th:name="idDelete"/>
                <input class="btn btn-danger" name="submit" type="submit" value="delete"/>
            </form>
        </td>

    </tr>

    </tbody>
</table>