본문 바로가기
자바의 봄(Spring)/프로젝트

SpringBoot-Movie-Thymeleaf-Project - 11 영화 디테일 페이지 만들기

by 종안이 2024. 4. 24.

1 . 영화 디테일 페이지 작성

 

@Test
@DisplayName("영화 정보에 관한 디테일한 내용을 얻어옵니다.")
public void getMovieDetails() {
    ResponseEntity<ApiResponseDetailsMovie> entity = rt.getForEntity("https://api.themoviedb.org/3/movie/643?append_to_response=string&language=ko-KR&api_key=" + apikey, ApiResponseDetailsMovie.class);
    ApiResponseDetailsMovie body = entity.getBody();
    System.out.println(body);
}

 

해당 api가 잘 작동하는지 확인해준다.  테스트를 돌려봤을때 아래처럼 결과가 정상적으로 나오는 것을 확인 할 수 있다. 

 

그러면 해당 API가 영화에 대한 디테일한 값을 가져오는 것을 확인했으니 이제 구체적인 페이지를 만들어본다. 

 

페이지를 만들 때는 Bootstrap Card를 이용해준다. 아래와 같이 작성 후 돌려보면 

 

### details.html 

<!DOCTYPE html>

<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{Part/header :: header}">
</head>
<nav th:replace="~{Part/navbar :: navigation}"></nav>
<body>


<div class="border border-dark">
    <div class="card" style="width: 18rem;">
        <img src="..." class="card-img-top" alt="...">
        <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            <a href="#" class="btn btn-primary">Go somewhere</a>
        </div>
    </div>
</div>
</body>
</html>

 

아래와 같이 카드가 나오는 것을 확인할 수 있다. 그러면 이제 사진을 리스트에서 나오는 것처럼 사진을 넣어준다. 

 

 

아래와 같이 코드를 작성해준다. 

 

## details.html 

 

<!DOCTYPE html>

<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{Part/header :: header}">
</head>
<nav th:replace="~{Part/navbar :: navigation}"></nav>
<body>


<div class="border border-dark">
    <div class="card mb-3">
        <td>
            <img th:src="${address + posterPath}" width="300" height="300">
        </td>
        <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
            <p class="card-text"><small class="text-body-secondary">Last updated 3 mins ago</small></p>
        </div>
    </div>

</div>
</body>
</html>

 

 

 

이미지 불러오는 부분에 디테일 ID의 주소를 추가했다. 그리고 사진 크기는 리스트에 있던 300으로 진행하면 아래와 같이 나온다.  

 

 

해당하는 ID의 영화의 사진을 불러왔다.

 

사진을 가져왔으니 , 이제 나머지 값들을 다 뿌려주면 된다. 

 

 

일단은 이렇게 진행했다. 나중에 값들을 더 추가할 것 인데 

 

내일 라섹 수술 예정이라 일주일 간 회복하고 다시 작업 할 수 있도록 하겠다. 

 

 

## details.html

<!DOCTYPE html>

<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{Part/header :: header}">
</head>
<nav th:replace="~{Part/navbar :: navigation}"></nav>
<body>

<div class="container" style="width: 500px; height: 600;">

    <div class="card text-center">
        <div style="text-align: center">
            <img th:src="${address + posterPath}" width="300" height="300">
        </div>
        <div class="card-body">
            <p class="card-text" th:text="${movieDetails.getOverview()}"></p>
        </div>
    </div>

</div>

</body>
</html>

댓글