Ejemplo n.º 1
0
 /*
  * 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";
 }
Ejemplo n.º 2
0
 @RequestMapping("blog/remove/{id}")
 public String removeBlog(@PathVariable int id) {
   Blog blog = blogService.findOne(id);
   blogService.delete(blog);
   return "redirect:/account";
 }