1

我的控制器中有以下方法

@RequestMapping(value = "processPurchase/{poid}", method = RequestMethod.DELETE)
public String processOrder(@PathVariable int poid) {
    // do some processing
    return acceptPurchaseForm;
}

我的 HTML

<form id="purchase-list-form" class="form-horizontal" action="/MyNewApp/processPurchase/" method="post">
<input type="hidden" name="_method" value="delete">
<input type="hidden" name="poid" value="">

有了上面我仍然得到以下错误

WARN : org.springframework.web.servlet.PageNotFound - Request method 'DELETE' not supported

任何帮助表示赞赏。

4

1 回答 1

5

首先,我假设您在 web.xml 中配置了HiddenHttpMethodFilter。需要将您的_methodwith value delete 转换为 DELETE RequestMethod

其次,poid在请求正文中传递,但在您的控制器中,您希望它在 URL 本身中传递。这可以解释为什么 Spring 无法映射请求。

编辑1:

要传入poidURL,您必须在生成 HTML 时将其包含在表单操作中。这取决于您的视图技术(我使用 Freemarker),但您需要执行以下操作:

<form action="/MyNewApp/processPurchase/${poid}" method="post">

假设 poid 被写入绑定到您的视图的模型中。

于 2013-03-25T07:38:43.847 回答