MCPcopy Create free account
hub / github.com/castello/spring_basic / CommentController

Class CommentController

ch4/CommentController.java:16–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14//@Controller
15//@ResponseBody
16@RestController
17public class CommentController {
18 @Autowired
19 CommentService service;
20
21// {
22// "pcno":0,
23// "comment" : "hihihi",
24// "commenter" : "asdf"
25// }
26 // 댓글을 수정하는 메서드
27 @PatchMapping("/comments/{cno}") // /ch4/comments/26 PATCH
28 public ResponseEntity<String> modify(@PathVariable Integer cno, @RequestBody CommentDto dto) {
29// String commenter = (String)session.getAttribute("id");
30 String commenter = "asdf";
31 dto.setCommenter(commenter);
32 dto.setCno(cno);
33 System.out.println("dto = " + dto);
34
35 try {
36 if(service.modify(dto)!=1)
37 throw new Exception("Write failed.");
38
39 return new ResponseEntity<>("MOD_OK", HttpStatus.OK);
40 } catch (Exception e) {
41 e.printStackTrace();
42 return new ResponseEntity<String>("MOD_ERR", HttpStatus.BAD_REQUEST);
43 }
44 }
45
46// {
47// "pcno":0,
48// "comment" : "hi"
49// }
50 // 댓글을 등록하는 메서드
51 @PostMapping("/comments") // /ch4/comments?bno=1085 POST
52 public ResponseEntity<String> write(@RequestBody CommentDto dto, Integer bno, HttpSession session) {
53// String commenter = (String)session.getAttribute("id");
54 String commenter = "asdf";
55 dto.setCommenter(commenter);
56 dto.setBno(bno);
57 System.out.println("dto = " + dto);
58
59 try {
60 if(service.write(dto)!=1)
61 throw new Exception("Write failed.");
62
63 return new ResponseEntity<>("WRT_OK", HttpStatus.OK);
64 } catch (Exception e) {
65 e.printStackTrace();
66 return new ResponseEntity<String>("WRT_ERR", HttpStatus.BAD_REQUEST);
67 }
68 }
69
70 // 지정된 댓글을 삭제하는 메서드
71 @DeleteMapping("/comments/{cno}") // DELETE /comments/1?bno=1085 <-- 삭제할 댓글 번호
72 public ResponseEntity<String> remove(@PathVariable Integer cno, Integer bno, HttpSession session) {
73// String commenter = (String)session.getAttribute("id");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected