페이징 유틸 추가

This commit is contained in:
ckx6954 2024-12-12 15:19:29 +09:00
parent cc5e87af0c
commit 6437f0e721
3 changed files with 55 additions and 1 deletions

View File

@ -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}"

View File

@ -18,3 +18,4 @@ lombokVersion=1.18.34
mybatisSpringBootVersion=3.0.3
jsonVersion = 20240303
mariadbClientVersion = 3.4.1
pageHelperVersion = 1.4.7

View File

@ -0,0 +1,50 @@
package io.company.localhost.utils;
import com.github.pagehelper.PageInfo;
import java.util.Map;
public class PageUtil {
public static PageInfo<Map<String , Object>> redefineNavigation(PageInfo<Map<String , Object>> 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;
}
}