jeudi 30 juillet 2020

trying to delete post on a webpage using REQUEST.delete method in spring mvc but code not working ,go through following snapshots and resolve my query

this the corresponding html code.....

<form th:action="@{/delete/(postId=${message.title})}" th:method="delete">
    <input type="submit" value="Delete" />

this is corresponding controller code........

@RequestMapping(value="/delete",method=RequestMethod.DELETE)
public String deletepost(@RequestParam(value="postId") String title){
    ps.deletepost(title);
    return "redirect:/";
}

this is deletepost method in service class

`public void deletepost(String title){ EntityManager em = emf.createEntityManager(); EntityTransaction transaction = em.getTransaction();

    try {
        transaction.begin();
        Post p=em.find(Post.class,title);
        System.out.println(p.getTitle());
        em.remove(p);
        transaction.commit();
    }catch(Exception e) {
        transaction.rollback();
    }
}`



Aucun commentaire:

Enregistrer un commentaire