MCPcopy Create free account
hub / github.com/castello/spring_basic / BoardController

Class BoardController

ch4/BoardController2.java:15–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13import java.util.*;
14
15@Controller
16@RequestMapping("/board")
17public class BoardController {
18 @Autowired
19 BoardService boardService;
20
21 @PostMapping("/modify")
22 public String modify(BoardDto boardDto, Integer page, Integer pageSize, RedirectAttributes rattr, Model m, HttpSession session) {
23
24 String writer = (String)session.getAttribute("id");
25 boardDto.setWriter(writer);
26
27 try {
28 if (boardService.modify(boardDto)!= 1)
29 throw new Exception("Modify failed.");
30
31 rattr.addAttribute("page", page);
32 rattr.addAttribute("pageSize", pageSize);
33 rattr.addFlashAttribute("msg", "MOD_OK");
34 return "redirect:/board/list";
35 } catch (Exception e) {
36 e.printStackTrace();
37 m.addAttribute(boardDto);
38 m.addAttribute("page", page);
39 m.addAttribute("pageSize", pageSize);
40 m.addAttribute("msg", "MOD_ERR");
41 return "board"; // 등록하려던 내용을 보여줘야 함.
42 }
43 }
44
45 @GetMapping("/write")
46 public String write(Model m) {
47 m.addAttribute("mode", "new");
48
49 return "board";
50 }
51
52 @PostMapping("/write") // insert니까 delete인 remove하고 동일
53 public String write(BoardDto boardDto, RedirectAttributes rattr, Model m, HttpSession session) {
54 String writer = (String)session.getAttribute("id");
55 boardDto.setWriter(writer);
56
57 try {
58 if (boardService.write(boardDto) != 1)
59 throw new Exception("Write failed.");
60
61 rattr.addFlashAttribute("msg", "WRT_OK");
62 return "redirect:/board/list";
63 } catch (Exception e) {
64 e.printStackTrace();
65 m.addAttribute("mode", "new"); // 글쓰기 모드로
66 m.addAttribute(boardDto); // 등록하려던 내용을 보여줘야 함.
67 m.addAttribute("msg", "WRT_ERR");
68 return "board";
69 }
70 }
71
72 @GetMapping("/read")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected