以前用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分頁的辦法,不知道大家覺得如何?呵呵!
br />我的msn:luyongfugx@hotmail.com