春天百里香叶传递对象属性到 href 按钮提交



我正在尝试执行表单操作,其中我为每个分组值显示选定的列表。用户在这些列表之一中选择一个值后,我想将此对象的名称作为参数放入按钮链接中,但参数值为空。我不知道我该怎么做。

这是我的代码:

在我的控制器中:

@RequestMapping(value="/teacher/depts", method=RequestMethod.GET)
public String depts(Model model) {
    model.addAttribute("deptsfields", fieldOfStudyService.findAllFieldsForAllDepartments());
    model.addAttribute("field", new FieldOfStudy());
    return "teacher/depts";
}
@RequestMapping(value="/deptsfields", method=RequestMethod.POST)
public String deptsfields(@ModelAttribute(value="field") FieldOfStudy field) {
    return "teacher/depts";
}

还有我的网页:

<form action="#" th:action="@{/deptsfields}" th:object="${field}" method="post">
    <table>
        <tr>
            <th>Wydział</th>
            <th>Kierunek</th>
        </tr>
        <tr th:each="entry : ${deptsfields}">
            <td th:text="${entry.getKey().details.departmentFullName}"
                th:value="${entry.getKey().details.departmentFullName}"
                th:field="*{details.department.details.departmentFullName}"></td>
            <td>
                <select id="fieldslist" class="form-control" th:field="*{details.fieldOfStudyName}">
                    <option selected="selected" value="">Wybierz...</option>
                    <option th:each="field : ${entry.getValue()}" th:value="${field.details.fieldOfStudyName}" th:text="${field.details.fieldOfStudyName}"></option>
                </select>
            </td>
        </tr>
    </table>
    <a th:href="@{/teacher/groups(field=${field.details.fieldOfStudyName}, dept=${field.details.department.details.departmentFullName})}" class="btn btn-info" role="button">Dalej</a>
</form>

单击按钮后,我被重定向到此页面:

http://localhost:8080/teacher/groups?field={here should be name but is empty}&dept={here should be name but is empty}

我做错了什么?

您的链接中有错误,请尝试此操作

  <a th:href="@{'/teacher/groups?field=' + ${field.details.fieldOfStudyName} + '&dept=' + ${field.details.department.details.departmentFullName}}" class="btn btn-info" role="button">Dalej</a>

相关内容

  • 没有找到相关文章

最新更新