@DeleteMapping
일반 방식이 아닌 REST 방식에서는
삭제로직을 Delete 방식으로 요청합니다.
@DeleteMapping 어노테이션으로
delete 방식을 요청해봅시다.
DELETE 요청을 처리하는 @DeleteMapping을 걸어주었고
@PathVariable을 통해 ?rno = {rno}와
같은 효과를 기대하도록 했습니다.
Delete는 return할 결과값이 없기 때문에
String 메서드로 작성했고
produces 에 String과 같은 TEXT_PLAIN_VALUE를 걸었습니다.
나머지를 이렇게 작성해주고 나면
이제 YARK에 url을 적용시켜보겠습니다.
완벽합니다.
아래는 remove 메서드의 전문입니다.
@DeleteMapping(value="/{rno}",
produces = {MediaType.TEXT_PLAIN_VALUE})
public ResponseEntity<String> remove(@PathVariable("rno") Long rno) {
ResponseEntity<String> entity = null;
try {
service.removeReply(rno);
entity = new ResponseEntity<String>("SUCCESS", HttpStatus.OK);
} catch(Exception e) {
entity = new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
return entity;
}