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