JS 전체 코드
const PAGE_SIZE = 10;
const PAGE_PER_BLOCK = 5;
function getPagination(pageno, totalcount) {
let countOfPage = Math.floor(totalcount/PAGE_SIZE)+1;
if(totalcount%PAGE_SIZE==0) {
countOfPage--;
}
let blockNo = Math.floor(pageno/PAGE_PER_BLOCK);
if(pageno%PAGE_PER_BLOCK==0) {
blockNo--;
}
const startPage = blockNo * PAGE_PER_BLOCK + 1;
const prev = startPage - 1;
let endPage = startPage + PAGE_PER_BLOCK - 1;
let next = endPage + 1;
if(endPage>=countOfPage) {
endPage = countOfPage;
next = 0;
}
return { prev, startPage, endPage, next};
}
const pagination = getPagination(11, 123);
console.log(pagination);
Java 전체 코드
package com.icia.example2;
class Pagination {
int prev;
int startPage;
int endPage;
int next;
}
public class PagingUtil {
final int PAGE_SIZE = 10;
final int PAGE_PER_BLOCK = 5;
Pagination getPagination(int pageno, int totalcount) {
int countOfPage = totalcount/PAGE_SIZE + 1;
if(totalcount%PAGE_SIZE==0) {
countOfPage--;
}
int blockNo = pageno/PAGE_PER_BLOCK;
if(pageno%PAGE_PER_BLOCK==0) {
blockNo--;
}
Pagination p = new Pagination();
p.startPage = blockNo * PAGE_PER_BLOCK + 1;
p.prev = p.startPage - 1;
p.endPage = p.startPage + PAGE_PER_BLOCK - 1;
p.next = p.endPage + 1;
if(p.endPage>=countOfPage) {
p.endPage = countOfPage;
p.next = 0;
}
return p;
}
}
JS와 Java 코드의 차이점
const PAGE_SIZE = 10;
const PAGE_PER_BLOCK = 5;
final int PAGE_SIZE = 10;
final int PAGE_PER_BLOCK = 5;
Pagination p = new Pagination();
p.startPage = blockNo * PAGE_PER_BLOCK + 1;
p.prev = p.startPage - 1;
p.endPage = p.startPage + PAGE_PER_BLOCK - 1;
p.next = p.endPage + 1;