【发布时间】:2011-07-05 05:59:44
【问题描述】:
我在一个 j2ee 项目中工作(pojo 层、Dao 层(休眠)、服务层(spring)、视图(spring mvc)) 我在每一行后面都有一个文章表,我想添加一个链接来删除它。
这是我的看法
<c:if test="${!empty articles}">
<table>
<tr>
<th>Article ID</th>
<th>Article Name</th>
<th>Article Desc</th>
<th>Added Date</th>
<th>operation</th>
</tr>
<c:forEach items="${articles}" var="article">
<tr>
<td><c:out value="${article.articleId}"/></td>
<td><c:out value="${article.articleName}"/></td>
<td><c:out value="${article.articleDesc}"/></td>
<td><c:out value="${article.addedDate}"/></td>
<td><a href="articles/${article.articleId}">delete</a></td>
</tr>
</c:forEach>
</table>
这里是要删除的控制器
@RequestMapping(value="/articles/{articleId}", method=RequestMethod.POST)
public String deleteContact(@PathVariable("articleId")
Integer articleId) {
articleService.removeArticle(articleId);
return "redirect:/articles.html";
}
这是服务层
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void removeArticle(Integer id) {
articleDao.removeArticle(id);
}
这是 Dao 层(我尝试找到文章然后将其删除)
public void removeArticle(Integer id) {
//to get the article
Article article = (Article) sessionFactory.getCurrentSession().load(
Article.class, id);
if (null != article) {
sessionFactory.getCurrentSession().delete(article);
}
}
但是当我运行项目并单击删除链接时,出现 404 错误 Etat HTTP 404 - /Spring3Hibernate/articles/1 说明请求的资源(/Spring3Hibernate/articles/1)不可用
有人可以帮我吗?
【问题讨论】:
-
您确定“a href”部分发送的是 POST 请求而不是 GET 请求吗?
标签: hibernate spring-mvc controller dao