diff --git a/myapp/src/main/java/com/example/myapp/BlogController.java b/myapp/src/main/java/com/example/myapp/BlogController.java index 4930fdd..c5c3a54 100644 --- a/myapp/src/main/java/com/example/myapp/BlogController.java +++ b/myapp/src/main/java/com/example/myapp/BlogController.java @@ -2,11 +2,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.DeleteMapping; +import java.util.List; + @Controller public class BlogController { @@ -14,7 +17,9 @@ public class BlogController { private PostRepository postRepository; @GetMapping("/posts") - public String listPosts() { + public String listPosts(Model model) { + List posts = postRepository.findAll(); + model.addAttribute("posts", posts); return "blog/index"; } diff --git a/myapp/src/main/resources/templates/blog/index.html b/myapp/src/main/resources/templates/blog/index.html index 540a9ca..568246c 100644 --- a/myapp/src/main/resources/templates/blog/index.html +++ b/myapp/src/main/resources/templates/blog/index.html @@ -1 +1,17 @@ -

List of Posts

+ + + +

Blog

+ +
+
+ Title +
+ +
+ Content +
+
+ +Submit a new post +