-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArticleController.java
More file actions
134 lines (113 loc) · 3.47 KB
/
ArticleController.java
File metadata and controls
134 lines (113 loc) · 3.47 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.spring.article.controller;
import com.spring.article.dto.Article;
import com.spring.article.service.ArticleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.inject.Inject;
@Controller
@RequestMapping("/article")
public class ArticleController {
private static final Logger logger = LoggerFactory.getLogger(ArticleController.class);
private final ArticleService articleService;
@Inject
public ArticleController(ArticleService articleService) {
this.articleService = articleService;
}
/**
* 전체 목록
*
* @param model
* @return
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Model model) {
logger.info("list ...");
model.addAttribute("articles", articleService.findAllArticle());
return "/article/list";
}
/**
* 해당 article 조회
*
* @param articleNo
* @param model
* @return
*/
@RequestMapping(value = "/read", method = RequestMethod.GET)
public String findOne(@RequestParam("articleNo") int articleNo, Model model) {
logger.info("findOne ...");
model.addAttribute("article", articleService.findByArticleNo(articleNo));
return "/article/read";
}
/**
* article 등록 화면으로 이동
*
* @return
*/
@RequestMapping(value = "/write", method = RequestMethod.GET)
public String writeGet() {
logger.info("write GET ...");
return "/article/write";
}
/**
* article 등록
*
* @param article
* @param redirectAttributes
* @return
*/
@RequestMapping(value = "/write", method = RequestMethod.POST)
public String writePost(Article article, RedirectAttributes redirectAttributes) {
logger.info("write POST ...");
logger.info(article.toString());
articleService.createArticle(article);
redirectAttributes.addFlashAttribute("msg", "regSuccess");
return "redirect:list";
}
/**
* article 수정 화면으로 이동
*
* @param articleNo
* @param model
* @return
*/
@RequestMapping(value = "/modify", method = RequestMethod.GET)
public String modifyGet(@RequestParam("articleNo") int articleNo, Model model) {
logger.info("modify Get ...");
model.addAttribute("article", articleService.findByArticleNo(articleNo));
return "/article/modify";
}
/**
* article 수정
*
* @param article
* @param redirectAttributes
* @return
*/
@RequestMapping(value = "/modify", method = RequestMethod.POST)
public String modifyPost(Article article, RedirectAttributes redirectAttributes) {
logger.info("modify POST ...");
articleService.updateArticle(article);
redirectAttributes.addFlashAttribute("msg", "modifySuccess");
return "redirect:list";
}
/**
* article 삭제
*
* @param articleNo
* @param redirectAttributes
* @return
*/
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String delete(@RequestParam("articleNo") int articleNo, RedirectAttributes redirectAttributes) {
logger.info("delete ...");
articleService.deleteArticle(articleNo);
redirectAttributes.addFlashAttribute("msg", "deleteSuccess");
return "redirect:list";
}
}