이전글
https://greed-yb.tistory.com/209
Controller
package com.example.practice.controller;
import com.example.practice.service.board.BoardService;
import com.example.practice.util.PageMaker;
import com.example.practice.util.SearchCriteria;
import com.example.practice.vo.BoardVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller
public class MainController {
@Autowired
private BoardService boardService;
/**
* 게시글 리스트
* @param model
* @param cri
* @return
* @throws Exception
*/
@GetMapping("/")
public String Main(Model model,@ModelAttribute SearchCriteria cri) throws Exception{
model.addAttribute("vo" , boardService.boardSelect(cri));
PageMaker pm = new PageMaker();
pm.setCri(cri);
pm.setTotalCount(boardService.totalCount(cri));
model.addAttribute("pm", pm);
return "index";
}
/**
* 게시글 작성 페이지
* @return
* @throws Exception
*/
@GetMapping("/board/create")
public String boardCreate() throws Exception{
return "BoardCreate";
}
/**
* 게시글 생성
* @param vo
* @return
* @throws Exception
*/
@PostMapping("/board/create")
public String boardCreate(@ModelAttribute BoardVo vo) throws Exception{
boardService.boardCreate(vo);
return "redirect:/";
}
/**
* 게시글 상세 페이지
* @param num
* @param model
* @return
* @throws Exception
*/
@GetMapping("/board/read")
public String boardRead(@RequestParam Integer num , Model model) throws Exception{
BoardVo vo = boardService.boardRead(num);
model.addAttribute("vo" , vo);
return "BoardRead";
}
/**
* 게시글 삭제
* @param num
* @return
* @throws Exception
*/
@GetMapping("/board/delete")
public String boardDelete(@RequestParam Integer num) throws Exception{
boardService.boardDelete(num);
return "redirect:/";
}
/**
* 게시글 수정 하기
* @param vo
* @return
* @throws Exception
*/
@PostMapping("/board/update")
public String boardUpdate(@ModelAttribute BoardVo vo) throws Exception {
boardService.boardUpdate(vo);
return "redirect:/";
}
}
댓글