@RequestMapping(value = "/{id}", method = RequestMethod.GET) public ModelAndView getComment(@PathVariable("id") Long id) { ModelAndView modelAndView = new ModelAndView("comment"); for (SavedComment comment : commentsService.getComments()) { if (id.longValue() == comment.id) { modelAndView.addObject("comment", CommentModel.fromComment(comment)); } } return modelAndView; }
@RequestMapping(method = RequestMethod.POST) public String postCommentForm(@ModelAttribute CommentForm commentForm) { commentsService.addComment(commentForm.toComment()); return "redirect:/comments"; }
@RequestMapping(method = RequestMethod.GET) public CommentsModel getComments() { List<SavedComment> comments = commentsService.getComments(); return CommentsModel.fromList(comments); }