-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPostController.java
More file actions
64 lines (44 loc) · 1.89 KB
/
PostController.java
File metadata and controls
64 lines (44 loc) · 1.89 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.cos.unishop.web;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import com.cos.unishop.domain.post.Post;
import com.cos.unishop.domain.post.PostRepository;
import com.cos.unishop.domain.user.UserRepository;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Controller
public class PostController {
private final PostRepository postRepository;
private final UserRepository userRepository;
private final HttpSession session;
// 최초 사이트 유입시에 들어가는 페이지 메인페이지로 가는 컨트롤러
@GetMapping({ "/", "/post" })
public String mainProduct(Model model) {
model.addAttribute("postsEntity", postRepository.findAll());
return "post/index";
}
//상품 페이지로 이동하는 컨트롤러
@GetMapping("/post/productPage")
public String productPage(Model model) {
model.addAttribute("postsEntity", postRepository.findAll());
return "post/productPage";
}
//상세정보페이지로 이동하는 컨트롤러
@GetMapping("post/{id}")
public String productDetail(@PathVariable int id, Model model) {
Post postEntity = postRepository.findById(id).get();
model.addAttribute("postEntity",postEntity);
return "post/detail";
}
//결제화면으로 이동하는 컨트롤러
@GetMapping("post/payment/{id}")
public String paymentPage(@PathVariable int id, Model model) {
Post postEntity = postRepository.findById(id).get();
model.addAttribute("postEntity", postEntity);
return "post/payment";
}
}