【问题标题】:Spring REST for DELETE Request Method用于删除请求方法的 Spring REST
【发布时间】:2013-03-14 15:08:35
【问题描述】:

我的控制器中有以下方法

@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

任何帮助表示赞赏。

【问题讨论】:

    标签: html spring-mvc spring-boot


    【解决方案1】:

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

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

    编辑1:

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

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

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

    【讨论】:

    • 你能告诉我如何在 URL 上传递参数的示例吗?
    猜你喜欢
    • 2021-09-22
    • 2021-10-05
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 2023-02-13
    • 2018-05-25
    相关资源
    最近更新 更多