What I am doing here is when I enter a bookname in textbook and click edit button. The textboxes below will show this book's all information. Then I can edit information in the same textboxes. In the end, I click update and the new information will be updated.I have edit part done, I can edit all information by given certain bookname. Now I am confused how to do update part, because both edit and update will use the same form(those textboxes), then how to handle post or get request? Someone can explain to me? Thank you.
controller:
@RequestMapping(value = "/edit", method=RequestMethod.GET)
public String getEditBookForm(@ModelAttribute("editBook") Book editBook, HttpServletRequest request) {
return "editbook";
}
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public ModelAndView processEditBookForm(@ModelAttribute("editBook") Book editBook ){
ModelAndView mv = new ModelAndView("editbook");
mv.addObject("resulteditBook",bookService.getBookByName(editBook.getBookName()) );
return mv;
}
jsp:
<form:form modelAttribute="editBook" >
<div>Enter BOOK NAME: <input type="text" name=bookName
style="width: 100">
<input type="submit" value="Edit" name="edit">
</div>
</form:form>
<form:form modelAttribute="updateBook" >
......
<p>
<input type="submit" value="Update" name="update">
</p>
</form:form>
Aucun commentaire:
Enregistrer un commentaire