From 64620ff3cb3e6b6142f9d1061f392b17103ce3aa Mon Sep 17 00:00:00 2001 From: Jwhyee Date: Mon, 26 Sep 2022 23:49:01 +0900 Subject: [PATCH] [DESIGN] #118 - Add main top 5 posts --- .../com/matdongsan/service/PostService.java | 4 +++ .../web/controller/MainPageController.java | 7 +++++- .../resources/templates/fragments/header.html | 20 +++++++-------- src/main/resources/templates/index.html | 25 +++++++++++++++++++ 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/matdongsan/service/PostService.java b/src/main/java/com/matdongsan/service/PostService.java index ce4d01bb..62b6e7f7 100644 --- a/src/main/java/com/matdongsan/service/PostService.java +++ b/src/main/java/com/matdongsan/service/PostService.java @@ -120,4 +120,8 @@ public Page getList(String keyword , int page , String searchType ,Pageabl return postRepository.findAll(pageable); } + + public List findTop5Post() { + return postRepository.findPostTop5(); + } } diff --git a/src/main/java/com/matdongsan/web/controller/MainPageController.java b/src/main/java/com/matdongsan/web/controller/MainPageController.java index d5eb3d26..4e0b18f9 100644 --- a/src/main/java/com/matdongsan/web/controller/MainPageController.java +++ b/src/main/java/com/matdongsan/web/controller/MainPageController.java @@ -1,8 +1,10 @@ package com.matdongsan.web.controller; +import com.matdongsan.service.PostService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller @@ -10,8 +12,11 @@ @Slf4j public class MainPageController { + private final PostService postService; + @GetMapping("/") - public String mainPageMapping() { + public String mainPageMapping(Model model) { + model.addAttribute("top5", postService.findTop5Post()); return "index"; } diff --git a/src/main/resources/templates/fragments/header.html b/src/main/resources/templates/fragments/header.html index 4c7d33f0..e2248ac1 100644 --- a/src/main/resources/templates/fragments/header.html +++ b/src/main/resources/templates/fragments/header.html @@ -273,16 +273,16 @@
Zinia Jessy
--> +

인기 포스팅 TOP 5

+