● ReplyController ( 댓글 등록 )
페이지 정보
본문
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.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.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;
}
}
- 이전글== 공란 == 24.06.23
- 다음글▲ localhost:8080/swagger-ui/index.html ( 댓글 등록 테스트 ) 24.06.23
댓글목록
등록된 댓글이 없습니다.