【发布时间】:2019-06-19 22:10:17
【问题描述】:
我得到以下警告
WARN [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-1) Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
我已经将方法设置为POST,但仍然出现上述错误。我的删除控制器收到此警告消息,除删除外,所有其他 CRUD 操作均正常工作。
请在下面找到代码 控制器映射删除产品:
@RequestMapping(value="/deleteproducts", method= RequestMethod.POST)
public String deleteProduct(@PathVariable("productId")int productId) {
IProductsDAO ip = new ProductsDAOImpl();
boolean b = ip.deleteProduct(productId);
if(b)
return "success";
else
return "deleteproducts";
这是我的 jsp 视图:
<body>
<form id="update product form" action="${pageContext.request.contextPath}/deleteproducts" method="post" role="form" style="display: none;">
<div class="form-group row">
<label for="product Id" class="col-sm-2 col-form-label">Id</label>
<div class="col-sm-10">
<input type="text" name="productId" class="form-control" id="productid" placeholder="Enter the product Id you want to delete">
</div>
</div>
</form>
</body>
delete方法调用的DAO实现:
public boolean deleteProduct(int productId)
{
boolean b = true;
try
{
sess.beginTransaction();
Products p = (Products)sess.load(Products.class, new Integer(productId));
sess.delete(p);
sess.getTransaction().commit();
}catch(Exception ex)
{
sess.getTransaction().rollback();
b = false;
}
return b;
}
现在有人可以告诉我应该对我的代码进行哪些更改来解决这个问题吗?
谢谢!
编辑 1:
@DeleteMapping(value="/deleteproducts/{productId}")
public String deleteProduct(@PathVariable("productId")int productId) {
IProductsDAO ip = new ProductsDAOImpl();
boolean b = ip.deleteProduct(productId);
if(b)
return "success";
else
return "deleteproducts";
}
仍然收到警告:
WARN [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-1) Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
【问题讨论】:
标签: spring hibernate spring-mvc web-applications