Because your JSP contains the new form for adding a new post, it will need the model attribute post
to be present when you go to /posts
.
@RequestMapping("/posts")
public String showAllPosts(ModelMap model) {
List<Post> posts = postDao.findAll();
model.addAttribute("post", new Post()); // Add empty form backing object
model.addAttribute("posts", posts);
return "posts";
}
You could even split out model creation to a separate method if you find you're having to create the model in multiple places. This will ensure that its always available.
@ModelAttribute("post")
public Post createModel() {
return new Post();
}