CRUD 실습
게시판 목록을 불러오는 함수 구현하기 [탐구/기록]
rexondex
2024. 9. 30. 16:58

컨트롤러의 getAllPosts(), 호출되면 매개인자 없이 모든 게시물을 읽는 기능을 수행하는 메서드입니다.
지금은 return "test"; 를 하게 되어 있는데, templates/test.html 을 반환하는 것입니다.

GET 메서드로 /posts 에 요청을 보내면, 컨트롤러가 test.html을 반환하게 되어있었으므로
호출용 test 페이지 를 반환한 것을 볼 수 있어요. test 페이지는 임의로 제가 작성한 것입니다.

그리고 아무 경로를 설정하지 않고, 기본 주소로 GET 요청을 보내면
스프링부트는 index.html 을 반환하게 되어있으므로 index.html을 반환한 것을 확인할 수 있습니다.



PostsRepository는 JpaRepository를 상속하는 인터페이스입니다.
JpaRepository<엔터티, PK타입> 을 상속(extends)하는 인터페이스를 만드는 것 만으로도
기본적인 CRUD 구현을 쉽게 할 수 있다고 하여 사용해보려 합니다.
인텔리제이에서 " 컨트롤 + i " 단축키를 누르면 상속관계에 있는 상위 클래스의 메서드를 쉽게 구현할 수 있습니다.
다음 계획은 JpaRepository로 DB에 접근해 데이터를 잘 가져오는지 확인해보고,
이것이 잘 되면 html 을 vscode로 기본적인 구조 설계와 디자인을 해볼 예정입니다.