我从模态窗口获取字段值有问题。

 <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModal" aria-hidden="true">
        <form th:action="@{/groups/add}" method="post">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="addModal">Add group</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="recipient-name" class="col-form-label">Group Name</label> <input type="text"
                                class="form-control" id="addName" name="name">
                        </div>
                        <div class="form-group">
                            <label for="recipient-name" class="col-form-label">Faculty</label> <select
                                class="form-control">
                                <option th:value=0>Faculty not assign</option>
                                <option th:each="faculty : ${faculties}" th:value="${faculty.id}"
                                    th:utext="${faculty.name}">Faculty</option>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                </div>
            </div>
        </form>
    </div>


在浏览器中,当我使用“添加”方法时,我可以从表格中选择任何学院,但可以,但是当我按下“保存”按钮时,只有名称返回给控制器,而没有有关学院的信息。我错过了什么?

最佳答案

最后,我解决了这个问题-我忘记给存储facultyId的字段命名。
这是错误:

<label for="recipient-name" class="col-form-label">Faculty</label>
<select class="form-control">


正确:

<label for="faculyId" class="col-form-label">Faculty</label>
<select class="form-control" id="addFaculty" name="facultyId">

09-11 20:49