Forms 有没有办法在SpringMVC上使用注释创建具有多个提交按钮的表单?

Forms 有没有办法在SpringMVC上使用注释创建具有多个提交按钮的表单?,forms,spring-mvc,annotations,Forms,Spring Mvc,Annotations,我正在尝试使用基于注释的SpringMVC创建简单的添加/删除表单。 “添加”功能进展顺利,但当我尝试添加另一个按钮到表单时,我卡住了 这是我的密码: 控制器操作: @RequestMapping(value = "/books/documentType.do", method = RequestMethod.GET) public String getDocType( @RequestParam(required = false, value = "id") Long id,

我正在尝试使用基于注释的SpringMVC创建简单的添加/删除表单。 “添加”功能进展顺利,但当我尝试添加另一个按钮到表单时,我卡住了

这是我的密码:

控制器操作:

@RequestMapping(value = "/books/documentType.do", method = RequestMethod.GET)
public String getDocType(
        @RequestParam(required = false, value = "id") Long id,
        ModelMap model) {

    DocTypeDTO docType = new DocTypeDTO();
    if (id != null)
        docType = docTypeConverter.getDTO(id);
    model.addAttribute("docType", docType);
    return "/books/documentType";
}

@RequestMapping(value = "/books/documentType.do", method = RequestMethod.POST)
public String setDocType(
        @ModelAttribute("docType") DocTypeDTO docType,
        BindingResult result,
        SessionStatus sessionStatus
) {
    docTypeValidator.validate(docType, result);
    if (result.hasErrors())
        return "/books/documentType";
    else {
        docTypeConverter.saveDTO(docType);
        sessionStatus.setComplete();
        return "redirect:/books/documentTypes.do";
    }

}
非常有标记的表格:

<form:form method="post" commandName="docType" id="editForm">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#dbdbdb">
    <tr>
        <td></td>
        <td>
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td class="spacer"><img src="/images/spacer.gif" width="116" height="1" border="0"/></td>
                    <td class="spacer"><img src="/images/spacer.gif" width="216" height="1" border="0"/></td>
                </tr>

                <tr>
                    <td class="form-cell-text-underlined">Отображать на сайте</td>
                    <td colspan="2">
                        <form:checkbox path="shownOnSite"/>
                    </td>
                </tr>

                <tr>
                    <td class="form-cell-text-underlined">Международный</td>
                    <td colspan="2">
                        <form:checkbox path="international"/>
                    </td>
                </tr>

                <tr>
                    <td class="form-cell-text-underlined">Внутренний код</td>
                    <td colspan="2">
                        <form:input path="internalCode"/>
                    </td>
                </tr>

                <tr>
                    <td class="form-cell-text-underlined">Код</td>
                    <td colspan="2">
                        <form:input path="code"/>
                        <form:errors path="code"/>
                    </td>
                </tr>

                <tr>
                    <td class="form-cell-text-underlined">Код IATA</td>
                    <td colspan="2">
                        <form:input path="codeIATA"/>
                    </td>
                </tr>

                <tr>
                    <td class="padded-underlined">Название</td>

                    <td colspan="2">
                        <form:input path="name"/>
                        <form:errors path="name"/>
                    </td>
                </tr>

                <tr>
                    <td class="padded-underlined">Название(Англ.)</td>

                    <td colspan="2">
                        <form:input path="nameEn"/>
                    </td>
                </tr>

                <tr>
                    <td colspan="3">
                        <input type="submit" value="Сохранить">
                    </td>
                </tr>

            </table>
        </td>
        <td></td>
    </tr>
</table>

Отображать на сайте
Международный
Внутренний код
Код
国际航空运输协会
Название
Название(Англ.)


谢谢

如果您真的希望表单上有两个提交按钮,可以使用如下Javascript(在本例中使用jQuery):


在SpringMVC3中,仅使用JSP和控制器就可以做到这一点。例如,这两个提交按钮处理“上一步”和“保存”操作:

<input value="Save" name="save" type="submit" id="btnSave" class="submit_button">
<input value="Previous" name="previous" type="submit" id="btnPrevious" class="submit_button">

你应该考虑接受PADYC的答案,因为它是对的。
@RequestMapping(value = "/books/documentTypeRemove.do", method = RequestMethod.POST)
public String removeDocType(...      
<input value="Save" name="save" type="submit" id="btnSave" class="submit_button">
<input value="Previous" name="previous" type="submit" id="btnPrevious" class="submit_button">
@RequestMapping(value="thisForm.form", params="save")
public String save() {
    // save
}

@RequestMapping(value="thisForm.form", params="previous")
public String doPreviousStuff() {
    // get mapping for previous page and return
}