我的控制器中有两个映射。这是一个 GET 映射:
@RequestMapping(value="/items/book-list/edit", method = RequestMethod.GET)
public String showEditBookPage(@RequestParam Long id, ModelMap model){
Book book = bookService.findBookById(id);
model.addAttribute("editForm", book);
LOG.info("Logged modified date once page is loaded: " + book.getModifyDate());
return "admin/book";
}
此映射仅用于显示小窗体的 book.jsp 页面。
我还有另一个具有相同值但使用 POST 方法的映射,用于提交表单。
@RequestMapping(value="/items/book-list/edit", method = RequestMethod.POST)
public String updateBook(@ModelAttribute("editForm") @Valid Book bookForm, BindingResult result, ModelMap model){
if(result.hasErrors()){
return "/admin/book";
}
LOG.info("Logged modified date before Save object: " + bookForm.getModifyDate());
LOG.info("Logged author before Save object: " + bookForm.getAuthor());
bookService.saveBook(bookForm);
LOG.info("Logged modified date after Save object: " + bookForm.getModifyDate());
LOG.info("Logged author after Save object: " + bookForm.getAuthor());
return "admin/book";
}
我的书.jsp:
<form:form method="post" modelAttribute="editForm" >
<div class="row border py-4">
<div class="col-sm-6">
<spring:bind path="title">
<div class="form-group">
<form:label path="title" for="title">Book title</form:label>
<form:input path="title" type="text" class="form-control" id="title" cssErrorClass="form-control border border-danger"/>
</div>
</div>
</form:form>
波斯汪
UYOU
浮云间
相关分类