/* * ModelAttribute param should be the same with the associated form. * In my case, <form:form commandName = "blogC", and ModelAttribute should be "blogC" */ @RequestMapping(value = "/account", method = RequestMethod.POST) public String addBlog( Model model, @Valid @ModelAttribute("blogC") Blog blog, BindingResult result, Principal principal) { if (result.hasErrors()) { return account(model, principal); } String name = principal.getName(); blogService.save(blog, name); return "redirect:/account"; }
@RequestMapping("blog/remove/{id}") public String removeBlog(@PathVariable int id) { Blog blog = blogService.findOne(id); blogService.delete(blog); return "redirect:/account"; }