스프링 부트 하루만에 배우기

12.7. 책 기록 컨트롤러 만들기

연서은 2024. 8. 15. 11:39

http://localhost:8080/book-log/create 주소에 bookId, comment, page JSON 데이터를 보내면 bookLogId, bookId, comment, page JSON 데이터를 응답하는 컨트롤러 메소드를 만들어보겠습니다. com.yse.dev.book.controller 패키지 아래에 BookLogController 컨트롤러를 생성합니다.


src/main/java > com.yse.dev.book.controller > BookLogController.java

@RestController  
@RequestMapping("/book-log")  
public class BookLogController {      
    private BookLogService bookLogService;  

    @Autowired  
    public void setBookLogService(BookLogService bookLogService) {  
        this.bookLogService = bookLogService;  
    }  

    @PostMapping("/create")  
    public ResponseEntity<BookLogCreateResponseDTO> insert(@RequestBody BookLogCreateDTO bookLogCreateDTO){  
        BookLogCreateResponseDTO bookLogCreateResponseDTO = this.bookLogService.insert(bookLogCreateDTO);  
        return ResponseEntity.ok(bookLogCreateResponseDTO);  
    }  
}