공통 적 인 페이지 클래스 ~
나중에 인터넷 에서 일반적인 방법 을 보 았 습 니 다. 이 방법 은 데이터 가 저 장 된 ResultSet 에서 안의 방법 으로 페이지 를 모 의 하여 매번 그 중에서 현재 페이지 의 데 이 터 를 꺼 내 는 것 입 니 다. 이런 방법 을 한 종류 에 봉 하면 ResultSet 을 조작 하 는 것 과 같 습 니 다. 효율 적 으로 는 상대 적 으로 높 지 않 지만 중용 성과 효율 을 고려 하면 비교적 절충 이 될 것 입 니 다.방법 이 죠. 물론 입 니 다. 구체 적 인 응용 은 실제 상황 에 따라 선택 하 는 것 이 좋 을 것 같 습 니 다.
공 부 를 하 는 이상 이해 만 으로 는 안 됩 니 다. 실현 에 옮 겨 야 자신의 것 이 될 수 있 습 니 다. 자신 은 이런 방법 에 따라 이런 종 류 를 써 보 았 습 니 다. 세부 적 으로 엄밀 하지 않 을 수도 있 습 니 다. 경험 이 없 는 학생 에 속 하지만 페이지 기능 은 실현 되 었 습 니 다.
인터페이스 Pageable 을 먼저 정 의 했 습 니 다.
public interface Pageable {
public boolean gotoPage(int curPage) throws SQLException;
public boolean beforeFirst() throws SQLException;
public boolean first() throws SQLException;
public boolean next() throws SQLException;
public boolean isAfterLast();
public int getTotalPage();
public int getTotal();
public int getCurPage();
public int getPageNum();
}
Pagination 을 통 해 구현:
import java.sql.ResultSet;
import java.sql.SQLException;
public class Pagination implements Pageable {
protected ResultSet rs = null;
protected int total; //
protected int pageNum; //
protected int curPage; //
protected int row; //
protected int rowFlag; //
protected int totalPage;//
/*
* ResultSet , , getResultSet() ResultSet
*/
public Pagination(ResultSet rs) throws SQLException{
this.rs = rs;
}
/*
*
*/
public Pagination(ResultSet rs,int pageNum) throws SQLException{
this(rs);
rs.last();
this.total = rs.getRow();
this.pageNum = pageNum;
if(this.pageNum <= 0){
throw new SQLException(" :" + this.pageNum);
}
if(total % pageNum == 0){
this.totalPage = total / pageNum;
}else{
this.totalPage = total / pageNum + 1;
}
}
/*
* curPage
*/
public boolean gotoPage(int curPage) throws SQLException{
this.curPage = curPage;
if(this.curPage > this.totalPage){
throw new SQLException(" " + this.curPage);
}
this.row = (curPage - 1) * this.pageNum + 1;
return rs.absolute(row);
}
/*
*
*/
public boolean beforeFirst() throws SQLException{
this.rowFlag = -1;
return this.rs.absolute(this.row - 1);
}
/*
*
*/
public boolean first() throws SQLException{
this.rowFlag = 0;
return this.rs.absolute(this.row);
}
/*
*
*/
public boolean next() throws SQLException{
// // , , next
// if(this.rowFlag > this.pageNum - 1){
// return false;
// }
// // , , next
// if(total % pageNum != 0 && this.curPage == this.totalPage){
// if(this.rowFlag > this.total % this.pageNum - 1){
// return false;
// }
// }
this.rowFlag++;
return rs.next();
}
/*
*
*/
public boolean isAfterLast(){
// ,
if(this.rowFlag > this.pageNum - 1){
return true;
}
// ,
if(total % pageNum != 0 && this.curPage == this.totalPage){
if(this.rowFlag > this.total % this.pageNum - 1){
return true;
}
}
return false;
}
/*
* getter ...
*/
public ResultSet getResultSet(){
return rs;
}
public int getTotalPage(){
return this.totalPage;
}
public int getTotal(){
return this.total;
}
public int getCurPage(){
return this.curPage;
}
public int getPageNum(){
return this.pageNum;
}
}
ResultSet 다 쓰 고 close () 기억 해! 계속 공부 중... 블 로그 채널 에 보 내 서 뭐 하 는 거 야?? 실험 해 봐.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
깊이 중첩된 객체를 정확히 일치 검색 - PostgreSQL목차 * 🚀 * 🎯 * 🏁 * 🙏 JSON 객체 예시 따라서 우리의 현재 목표는 "고용주"사용자가 입력한 검색어(이 경우에는 '요리')를 얻고 이 용어와 정확히 일치하는 모든 사용자 프로필을 찾는 것입니다. 즐거운 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.