forked from machen2/ApprenticeLearningApp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPostController.java
More file actions
38 lines (30 loc) · 1.04 KB
/
PostController.java
File metadata and controls
38 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.pillar.pillarLearningCenter.controller;
import com.pillar.pillarLearningCenter.model.Post;
//import com.pillar.pillarLearningCenter.service.PostService;
import com.pillar.pillarLearningCenter.repository.PostRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Controller
public class PostController {
@Autowired
private PostRepository postService;
@GetMapping("/posts")
public String posts(Model model) {
List<Post> allPosts = postService.findAll();
model.addAttribute("postList", allPosts);
return "posts";
}
@GetMapping("/posts/new")
public String postsNew(Model model) {
model.addAttribute("post", new Post());
return "new";
}
@PostMapping("/posts/new")
public String submitPost(@ModelAttribute Post post) {
postService.save(post);
return "redirect:/posts";
}
}