애플리케이션 설계
< NcsTest15 – src/main/java – ncstest.controller – (Class) BoardController >
< NcsTest15 – src/main/java – ncstest.controller – (Class) ReplyController >
package ncstest.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
@Controller
public class BoardController {
// 게시글 목록
@GetMapping("/boards")
public String listPage(Model model) {
return "/board/list";
}
// 게시글 작성 화면
@GetMapping("/boards/write")
public String writePage() {
return "/board/write";
}
// 게시글 작성 처리
@PostMapping("/boards/write")
public String write() {
return "redirect:/boards";
}
// 게시글 상세 화면
@GetMapping("/boards/{bno}")
public String detailPage(@PathVariable long bno, Model model) {
return "/board/detail";
}
// 게시글 수정
@PutMapping("/boards/{bno}")
public String update(@PathVariable long bno) {
return "redirect:/boards/"+bno;
}
// 게시글 삭제
@DeleteMapping("/boards/{bno}")
public String delete(@PathVariable long bno) {
return "redirect:/boards";
}
}
package ncstest.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class ReplyController {
// 댓글 목록
@GetMapping("/boards/{bno}/replies")
public String repliesPage(@PathVariable long bno, Model model) {
return "/reply/list";
}
// 댓글 작성 처리
@ResponseBody
@PostMapping("/boards/{bno}/replies")
public void repliesWrite(@PathVariable long bno) {
}
// 댓글 수정
@ResponseBody
@PutMapping("/boards/{bno}/replies/{rno}")
public void repliesUpdate(@PathVariable long bno, @PathVariable long rno) {
}
// 댓글 삭제
@ResponseBody
@DeleteMapping("/boards/{bno}/replies/{rno}")
public void repliesDelete(@PathVariable long bno, @PathVariable long rno) {
}
}