[2023-11-07]

main.html 타임리프로 DB 값 가져오기

Untitled

<!DOCTYPE html>
<html lang="ko"
      xmlns:th="<http://www.thymeleaf.org>">

<head>
    <title>main</title>
    <link rel="stylesheet" href="<https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css>">
    <style>
        .image-size img {
            width: 300px;
            height: 300px;
        }

        .figcaption-center {
            text-align: center;
        }

    </style>
</head>

<body>
    <header th:replace="~{/header/header :: headerFragment}"></header>

    <div class="container-fluid">
        <div class="row">

        <!-- Sidebar -->
        <header th:replace="~{/sidebar/sidebar :: sidebarFragment}"></header>

        <!-- Main -->
        <main role="main" class="col-md-9 col-lg-10 px-md-4" style="margin-left: 200px">

            <!-- 검색창 추가 -->
            <br>
            <div class="input-group">
                <div class="input-group-prepend">
                    <select class="custom-select rounded-pill" id="search-type">
                        <option value="title">통합검색</option>
                        <option value="title">제목</option>
                        <option value="author">작가</option>
                        <option value="publisher">출판사</option>
                    </select>
                </div>
                <input type="search" class="form-control rounded-pill" id="search-input" placeholder=" " aria-label="Search" aria-describedby="search-addon" />
                <button type="button" class="btn btn-outline-primary rounded-pill" style="color: black; border-color: #E2ECE2; background-color: #E2ECE2;" onclick="performSearch()">검색</button>
            </div>
            <br>

            <!-- 이미지 출력 폼 -->
            <form>
                <div class="form-row">
                    <div class="form-group col-md-4" th:each="book : ${Books}">
                        <div th:each="image : ${book.images}" class="image-size" style="text-align: center;">
                            <a th:href="@{/board/detail/{bookId}(bookId=${book.book_id})}">
                                <img th:src="${image.image_url}" th:alt="${book.title}" style="display: inline-block;">
                            </a>
                        </div>
                        <div style="margin-bottom: 10px;"></div>
                        <figcaption class="figcaption-center">
                            <a th:href="@{/board/detail/{bookId}(bookId=${book.book_id})}">
                                <span th:text="${book.title}"></span>
                            </a>
                            <div style="background-color: #E2ECE2; border: 1px solid #E2ECE2; border-radius: 20px; color: black; font-size: 14px; padding: 5px 10px; pointer-events: none; display: inline-block;">
                                <span th:text="${book.transactions.status}"></span>
                            </div>
                        </figcaption>
                    </div>
                </div>
            </form>

        </main>

        </div>
    </div>

<footer th:replace="~{/footer/footer :: footerFragment}"></footer>
</body>
</html>

Controller에서 Books 엔티티를 사용하지 않고, BookDTO를 사용

Books 엔티티를 바로 사용하지 말고 DTO로 변환하여 사용해야지 좋다고 한다.