From 6437f0e721a186aaeb7af9f4ac52da07865ca3b6 Mon Sep 17 00:00:00 2001 From: ckx6954 Date: Thu, 12 Dec 2024 15:19:29 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=95=20=EC=9C=A0?= =?UTF-8?q?=ED=8B=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ gradle.properties | 3 +- .../io/company/localhost/utils/PageUtil.java | 50 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/company/localhost/utils/PageUtil.java diff --git a/build.gradle b/build.gradle index 9fffc13..ace8992 100644 --- a/build.gradle +++ b/build.gradle @@ -96,6 +96,9 @@ dependencies { /** mariaDB */ implementation "org.mariadb.jdbc:mariadb-java-client:${mariadbClientVersion}" + /** pageHelper */ + implementation "com.github.pagehelper:pagehelper-spring-boot-starter:${pageHelperVersion}" + /** mybatis-spring-boot-starter */ implementation "org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatisSpringBootVersion}" diff --git a/gradle.properties b/gradle.properties index dd16a6c..26c7ded 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,4 +17,5 @@ junitJupiterVersion=5.9.3 lombokVersion=1.18.34 mybatisSpringBootVersion=3.0.3 jsonVersion = 20240303 -mariadbClientVersion = 3.4.1 \ No newline at end of file +mariadbClientVersion = 3.4.1 +pageHelperVersion = 1.4.7 \ No newline at end of file diff --git a/src/main/java/io/company/localhost/utils/PageUtil.java b/src/main/java/io/company/localhost/utils/PageUtil.java new file mode 100644 index 0000000..97ce83a --- /dev/null +++ b/src/main/java/io/company/localhost/utils/PageUtil.java @@ -0,0 +1,50 @@ +package io.company.localhost.utils; + +import com.github.pagehelper.PageInfo; + +import java.util.Map; + +public class PageUtil { + + + public static PageInfo> redefineNavigation(PageInfo> list){ + + // 페이지 배열 + int[] nav = list.getNavigatepageNums(); + // 몇 페이지 + int navigatePages = list.getNavigatePages(); + // 현재 페이지 + int currentPage = list.getPageNum(); + // 총 페이지 수 + int total = list.getPages(); + // 배열 길이 + int navLength = nav.length; + + if(navLength != 0){ + int ff = (int) Math.ceil((double) nav[navLength -1] / navigatePages); + + int gg = ff * navigatePages; + + if(gg - currentPage >= navigatePages){ + gg = gg - navigatePages; + }else if(gg == 0){ + gg = navigatePages; + } + + if(gg > total && total >= navigatePages ){ + navLength = total%navigatePages; + } + + int[] nav2 = new int[navLength]; + gg = gg - (navigatePages - 1); + for(int i = 0 ; i < nav2.length ; i++){ + nav2[i] = gg++; + } + list.setNavigatepageNums(nav2); + list.setNavigateFirstPage(nav2[0]); + list.setNavigateLastPage(nav2[nav2.length -1]); + } + + return list; + } +}