BoardController
페이지 정보
본문
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";
}
}
- 이전글PageMaker 24.06.10
- 다음글BoardService 24.06.10
댓글목록
등록된 댓글이 없습니다.