● ReplyController ( 댓글 조회 )
페이지 정보
![profile_image](https://dancepkt.cafe24.com/data/member_image/ad/admin.gif?1630310007)
본문
package web.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.MediaType;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import web.dto.PageRequestDTO;
import web.dto.PageResponseDTO;
import web.dto.ReplyDTO;
import web.service.ReplyService;
@RestController
@Log4j2
@RequestMapping("/replies")
@RequiredArgsConstructor
public class ReplyController {
private final ReplyService replyService;
@Operation(summary = "Replies POST", description = "POST 방식으로 댓글 등록")
@PostMapping(value = "/", consumes = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Long> register(@Valid @RequestBody ReplyDTO replyDTO, BindingResult bindingResult) throws BindException {
log.info(replyDTO);
if(bindingResult.hasErrors()) {
throw new BindException(bindingResult);
}
Map<String, Long> resultMap = new HashMap<>();
Long rno = replyService.register(replyDTO);
resultMap.put("rno", rno);
return resultMap;
}
@Operation(summary = "Replies of Board", description = "GET 방식으로 댓글 목록")
@GetMapping(value = "/list/{bno}")
public PageResponseDTO<ReplyDTO> getList(@PathVariable("bno") Long bno, PageRequestDTO pageRequestDTO){
PageResponseDTO<ReplyDTO> responseDTO = replyService.getListOfBoard(bno, pageRequestDTO);
return responseDTO;
}
@Operation(summary = "Read Reply", description = "GET 방식으로 댓글 조회")
@GetMapping(value = "/{rno}")
public ReplyDTO getReplyDTO(@PathVariable("rno") Long rno) {
ReplyDTO replyDTO = replyService.read(rno);
return replyDTO;
}
}
- 이전글▲ localhost:8080/swagger-ui/index.html ( 댓글 조회 예외 테스트 ) 24.06.23
- 다음글▲ localhost:8080/swagger-ui/index.html 24.06.23
댓글목록
등록된 댓글이 없습니다.