diff --git a/src/main/java/com/matdongsan/service/PostService.java b/src/main/java/com/matdongsan/service/PostService.java index ce4d01b..62b6e7f 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 d5eb3d2..4e0b18f 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 4c7d33f..e2248ac 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

+