Spring Mvc Controller - 删除问题

Ell*_*med 2 dao hibernate controller spring-mvc

我在一个j2ee项目(pojo层,Dao层(hibernate),服务层(spring),View(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>
Run Code Online (Sandbox Code Playgroud)

这是要删除的控制器

@RequestMapping(value="/articles/{articleId}", method=RequestMethod.POST)
public String deleteContact(@PathVariable("articleId")
Integer articleId) {

    articleService.removeArticle(articleId);

    return "redirect:/articles.html";
}
Run Code Online (Sandbox Code Playgroud)

这是服务层

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void removeArticle(Integer id) {
    articleDao.removeArticle(id);
}
Run Code Online (Sandbox Code Playgroud)

这是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);
    }

}
Run Code Online (Sandbox Code Playgroud)

但是当我运行项目并单击删除链接时,我有404错误Etat HTTP 404 - /Spring3Hibernate/articles/1描述请求的资源(/ Spring3Hibernate/articles/1)不可用

有人能帮助我吗?

dan*_*nik 5

 <td><a href="articles/${article.articleId}">delete</a></td>
Run Code Online (Sandbox Code Playgroud)

这是标准的GET请求,但您的控制器映射到POST.

@RequestMapping(value="/articles/{articleId}", method=RequestMethod.POST)
Run Code Online (Sandbox Code Playgroud)

此外,它看起来非常大的安全问题.我可以编写非常简单的10行程序,它将使用get/post请求从/ articles/1调用/ articles/{any number}并删除整个数据.我建议在设计此类应用程序时将其考虑在内.