본문 바로가기

IT/ETC

Controller

반응형

1. BoardController

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
 
 
import org.springframework.stereotype.Controller;
 
 
@Controller
public class BoardController {
 
    @Autowired
    BoardService boardService;
    
    @Autowired
    CommentService commentService;
    
    @RequestMapping("boardList")
    public String toBoardList(Model model, Board board,
            @RequestParam(required = false, defaultValue= "1")int page,
            @RequestParam(required = false, defaultValue= "1")int range) throws Exception {
        //전체 게시글 개수
        int listCnt = boardService.getBoardListCnt();
        
        //Pagination 
        Pagination pagination = new Pagination();
        pagination.pageInfo(page, range, listCnt);
        
        model.addAttribute("pagination", pagination);
        model.addAttribute("board", boardService.selectAll(pagination));
        return "board/boardList";
    }
    
    @RequestMapping("boardWrite")
    public String toBoardWrite() {
        return "board/boardWrite";
    }
    
    @RequestMapping("boardInsert")
    public String boardInsert(Board board) {
        return "redirect:boardList";
    }
    
    @RequestMapping("boardView")
    public String toBoardView(Board board, Model model) {
        model.addAttribute("board"boardService.select(board));
        model.addAttribute("comment", commentService.selectAll(board.getBoardId()));
        return "board/boardView";
    }
    
    @RequestMapping("toBoardEdit")
    public String toBoardEdit(Board board, Model model) {
        model.addAttribute("board"boardService.select(board));
        return "board/boardEdit";
    }
    
    @RequestMapping("boardEdit")
    public String boardEdit(Board board) {
        return "redirect:boardView?boardId=" + board.getBoardId();
    }
    
    @RequestMapping("boardDelete")
    public String boardDelete(Board board) {
        return "redirect:boardList";
    }
    
    @RequestMapping("toBoardReply")
    public String toBoardReply(Board board, Model model) {
        model.addAttribute("board", board);
        return "board/boardReply";
    }
    
    @RequestMapping("boardReply")
    public String BoardReply(Board board, HttpServletRequest request) {
        return "redirect:boardList";
    }
    
    @RequestMapping("search")
    public String search(@RequestParam("search"String search, @RequestParam("type"String type, Model model) {
        model.addAttribute("result"boardService.search(search, type));
        System.out.println(boardService.search(search, type));
        return "board/search";
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. CommentController

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
 
import org.springframework.stereotype.Controller;
 
 
@Controller
public class CommentController {
 
    @Autowired
    CommentService commentService;
    
    @RequestMapping("postComment")
    public String postComment(Comment comment) {
        return "redirect:boardView?boardId=" + comment.getBoardId();
    }
    
    @RequestMapping("deleteComment")
    public String deleteComment(Comment comment) {
        return "redirect:boardView?boardId="+ comment.getBoardId();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. MemberController

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
 
 
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
 
 
@Controller
public class MemberController {
 
    @Autowired 
    MemberService memberService;
 
    @RequestMapping("toLogin")
    public String toLogin() {
        
        return "member/login";
    }
    
    @RequestMapping("loginCheck")
    public String login(Boardmember member, HttpSession session, Model model) {
        if(memberService.checkMember(member)) {
            model.addAttribute("success""Login Success!");
            session.setAttribute("session", member);
            return "home";
        } else {
            model.addAttribute("fail""Try reentering username or password");
            return "member/login";
        }
    }
    
    @RequestMapping("toRegister")
    public String toRegister() {
        return "member/register";
    }
    
    @RequestMapping("register")
    public String register(Boardmember member, Model model, BindingResult bindingResult) {
        memberService.registerMember(member);
        if(bindingResult.hasErrors()) {
            return "member/register";
        } else {
            model.addAttribute("success""Register Success! Now login");
        }
        
        
        return "home";
    }
    
    @RequestMapping("logout")
    public String logout(HttpSession session, Model model) {
        session.invalidate();
        model.addAttribute("success""Logout Success!");
        return "home";
    }
    
    
    
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

반응형

'IT > ETC' 카테고리의 다른 글

Various html  (0) 2019.11.14
Settings  (0) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14