ibatis分頁做法

ibatis分頁做法 

以前用ibatis做分頁的時候,是用的queryforList()方法,後面感覺不好,因爲我看過一些ibatis的源碼,感覺它好像是用resultset的滾動遊標的方式實現的,這樣如果數據量大會不會有問題呢?以前用jdbc的時候是用一個stringbuffer來構造oracle(我們用的是oracle,其它數據庫有各自的方法)的三層鉗套的sql語句的,做ibatis時語句都是寫在xml配置文件裏面的,不好做這種構造工作。後來想了葛簡單的辦法:
在domain包裏面定義一個basedomain類:
public class Basedomain {

private int start;
private int end;
/**
* @return Returns the end.
*/
public int getEnd() {
return end;
}
/**
* @param end The end to set.
*/
public void setEnd(int end) {
this.end = end;
}
/**
* @return Returns the start.
*/
public int getStart() {
return start;
}
/**
* @param start The start to set.
*/
public void setStart(int start) {
this.start = start;
}

}
包含兩個成員變量
start: 取數據時的起始位置
end: 取數據時的結束位置

然後各個實體類將繼承這個basedomain類
然後在要分頁的sql語句裏面加上三層鉗套的sql語句,兩個rownum參數分別就是上面的start和end。
以下是一個示例:
select * from (select my_table.*,rownum as my_rownum from (
select name,password from user  order by id desc
=#start# ]]>   
這就是我的ibatis分頁的辦法,不知道大家覺得如何?呵呵!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章