메인 페이지

루민 ·2023년 4월 14일
0
post-thumbnail

📝메인 페이지

메인 페이지는 부트 스트랩의 무료 쇼핑몰 템플릿을 참고하였습니다!

HomeController

@Controller
@Slf4j
@RequiredArgsConstructor
public class HomeController {

    private final ItemService itemService;
    private final ItemImageService itemImageService;
    private final FileHandler fileHandler;

    @GetMapping("/")
    public String home(Model model, HttpServletRequest request) {
        List<Item> items = itemService.findItems();
       	model.addAttribute("items", items);
        
        HttpSession session = request.getSession(false);

        //비로그인 사용자
        if (session == null || session.getAttribute(SessionConst.LOGIN_MEMBER) == null) {
            log.info("home controller");
            return "home";
        }

        //로그인된 사용자
        log.info("userHome Controller");
        return "userHome";

    }
  • 로그인 기능구현 에서 로그인에 성공하면 세션을 생성하고 세션에 회원정보를 보관하였습니다.
  • HomeController에서는 세션을 확인해서 세션이 없으면 비로그인 유저 페이지로 이동하고 세션이 생성되어있으면 로그인 유저 홈으로 이동합니다.


비로그인 유저 메인 페이지

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <title>Roominis</title>
    <!-- Favicon-->
    <link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
    <!-- Bootstrap icons-->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
    <!-- Core theme CSS (includes Bootstrap)-->
    <link href="css/styles.css" rel="stylesheet" />
</head>
<body>

<!-- Navigation-->
<nav class="navbar navbar-expand-lg navbar-light bg-light" >
    <div class="container px-4 px-lg-5">
        <a class="navbar-brand" th:href="@{/}">Roominis</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">

            <ul class="navbar-nav me-auto mb-2 mb-lg-0 ms-lg-4">
            </ul>

            <form th:action="@{/members}" class="d-flex">
                <button class="btn btn-outline-secondary"
                        type="submit">
                    로그인
                </button>
            </form>
            &nbsp;
              <form th:action="@{/members/new}" class="d-flex">
                <button class="btn btn-outline-secondary" type="submit">
                    회원가입
                </button>
            </form>

        </div>
    </div>
</nav>
<!-- Header-->
<header class="bg-dark py-5">
    <div class="container px-4 px-lg-5 my-5">
        <div class="text-center text-white">
            <h1 class="display-4 fw-bolder">Roominis</h1>
            <p class="lead fw-normal text-white-50 mb-0">루미니스 쇼핑몰에 오신것을 환영합니다</p>
        </div>
    </div>
</header>
<!-- Section-->
<section class="py-5">
    <div class="container px-4 px-lg-5 mt-5">
        <div class="row gx-4 gx-lg-5 row-cols-2 row-cols-md-3 row-cols-xl-4 justify-content-center">

            <!-- 아무 상품도 등록하지 않았을 경우 -->
            <div th:if="${#lists.isEmpty(items)}">
                <div class="card h-100">
                    <!-- Product image-->
                    <img class="card-img-top" src="https://dummyimage.com/450x300/dee2e6/6c757d.jpg" alt="..." />
                    <!-- Product details-->
                    <div class="card-body p-4">
                        <div class="text-center">
                            <!-- Product name-->
                            <h5 class="fw-bolder">상품 등록 대기중</h5>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col mb-5" th:each="item : ${items}">
                <div class="card h-100">
                    <!-- Product image-->
                    <img class="card-img-top" style="width: 268px; height: 300px" th:src="|/images/${item.getItemImageList().get(0).getStoreName()}|" alt="..." />
                    <!-- Product details-->
                    <div class="card-body p-4">
                        <div class="text-center">
                            <!-- Product name-->
                            <h5 class="fw-bolder" th:text="${item.getName()}">Product</h5>
                            <!-- Product price-->
                            <p th:text="|${item.price}₩|">price</p>
                        </div>
                    </div>
                    <!-- Product actions-->
                    <div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
                        <div class="text-center">
                            <a class="btn btn-outline-dark mt-auto" href="#" th:href="@{/items/{id} (id=${item.id})}">View options</a></div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</section>
<!-- Footer-->
<footer class="py-5 bg-dark">
    <div class="container"><p class="m-0 text-center text-white">Copyright &copy; Your Website 2022</p></div>
</footer>
<!-- Bootstrap core JS-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Core theme JS-->
<script src="js/scripts.js"></script>
</body>
</html>



로그인 유저 메인 페이지

<!-- Navigation-->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container px-4 px-lg-5">
        <a class="navbar-brand" th:href="@{/}">Roominis</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">

            <ul class="navbar-nav me-auto mb-2 mb-lg-0 ms-lg-4">
                <!--                <li class="nav-item"><a class="nav-link" href="#!">About</a></li>-->
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" id="navbarDropdown" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">상품 관리</a>
                    <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <li><a class="dropdown-item" th:href="@{/items/new}">상품 등록</a></li>
                        <li><hr class="dropdown-divider" /></li>
                        <li><a class="dropdown-item" th:href="@{/items}">상품 관리</a></li>
                    </ul>
                </li>
            </ul>
            &nbsp
            <form th:action="@{/logout}" class="d-flex" method="post">
                <button class="btn btn-outline-dark"
                        type="submit">
                    로그아웃
                </button>
            </form>
            &nbsp;
            <form class="d-flex">
                <button class="btn btn-outline-dark" type="submit">
                    <i class="bi-cart-fill me-1"></i>
                    Cart
                    <span class="badge bg-dark text-white ms-1 rounded-pill">0</span>
                </button>
            </form>

        </div>
    </div>
</nav>

상품 등록 전



상품 등록 후



참고

https://startbootstrap.com/template/shop-homepage

0개의 댓글