BoardController > SPRINGBOOT

본문 바로가기
사이트 내 전체검색

SPRINGBOOT

BoardController

페이지 정보

profile_image
작성자 관리자
댓글 0건 조회 65회 작성일 24-06-10 13:36

본문

package web.controller;


import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;


import web.dto.BoardDto;

import web.dto.Criteria;

import web.dto.PageMaker;

import web.service.BoardService;


@Controller

public class BoardController {


@Autowired

private BoardService boardService;


@GetMapping("/board/list")

public ModelAndView criSearchList(Criteria cri, PageMaker pm) throws Exception {

ModelAndView mv = new ModelAndView();


List<BoardDto> list = boardService.selectSearchList(cri);

mv.addObject("list", list);


pm.setCri(cri); // 페이징

pm.setTotalCount(boardService.listSearchCount(cri)); // 총 게시물 수

mv.addObject("pm",pm);


return mv;

}


//@GetMapping("/board/list")

public ModelAndView criPageList(Criteria cri, PageMaker pm) throws Exception {

ModelAndView mv = new ModelAndView();


List<BoardDto> list = boardService.selectPageList(cri);

mv.addObject("list", list);


pm.setCri(cri); // 페이징

pm.setTotalCount(boardService.listCount(cri)); // 총 게시물 수

mv.addObject("pm",pm);


return mv;

}


//@GetMapping("/board/list")

public ModelAndView criList(Criteria cri) throws Exception {

ModelAndView mv = new ModelAndView();


List<BoardDto> list = boardService.selectCriList(cri);

mv.addObject("list", list);


return mv;

}


//@GetMapping("/board/list")

public ModelAndView openBoardList() throws Exception {

//① 생성자에 값이 존재 한다면 /board/list.html 찾아간다.

ModelAndView mv = new ModelAndView("/board/list");


//② 생성자에 값이 없다면 매핑 값 '/board/list' + '.html' 찾아간다.

//ModelAndView mv = new ModelAndView();


List<BoardDto> list = boardService.selectBoardList();

mv.addObject("list", list);


return mv;

}


@GetMapping("/board/write")

public void openWrite() throws Exception {


}


@PostMapping("/board/write")

public String openWritePost(BoardDto board) throws Exception {

boardService.insertBoard(board);


return "redirect:list";

}


@GetMapping("/board/view")

public ModelAndView openView(@RequestParam("boardIdx") int boardIdx) throws Exception {


BoardDto board = boardService.selectBoardDetail(boardIdx);


ModelAndView mv = new ModelAndView();

mv.addObject("board", board);


mv.addObject("changeLine", '\n'); //개행처리

// thymeleaf에서는 '' 와 'n'를 따로 인식해서 변수로 전달처리


return mv;

}


@GetMapping("/board/modify")

public ModelAndView ModifyGet(@RequestParam("boardIdx") int boardIdx) throws Exception {


BoardDto board = boardService.selectBoardDetail(boardIdx);


ModelAndView mv = new ModelAndView();

mv.addObject("board", board);


return mv;

}


@PostMapping("/board/modify")

public String openModifyPost(BoardDto board) throws Exception {

boardService.updateBoard(board);


return "redirect:list";

}


@GetMapping("/board/delete")

public String openModifyPost(@RequestParam("boardIdx") int boardIdx) throws Exception {

boardService.deleteBoard(boardIdx);


return "redirect:list";

}


}


댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

공지사항
자유게시판
질문답변
1:1문의

 

별명 : 터푸가위
주소 : 부산시 동래구 명장로20번길 90
대표 : 박규태
메일 : dancepkt@******.com

접속자집계

오늘
246
어제
160
최대
10,760
전체
273,855
Copyright © dancePKT . All rights reserved.