以前用ibatis做分頁(yè)的時(shí)候,是用的queryforList()方法,后面感覺(jué)不好,因?yàn)槲铱催^(guò)一些ibatis的源碼,感覺(jué)它好像是用resultset的滾動(dòng)游標(biāo)的方式實(shí)現(xiàn)的,這樣如果數(shù)據(jù)量大會(huì)不會(huì)有問(wèn)題呢?以前用jdbc的時(shí)候是用一個(gè)stringbuffer來(lái)構(gòu)造oracle(我們用的是oracle,其它數(shù)據(jù)庫(kù)有各自的方法)的三層鉗套的sql語(yǔ)句的,做ibatis時(shí)語(yǔ)句都是寫(xiě)在xml配置文件里面的,不好做這種構(gòu)造工作。后來(lái)想了葛簡(jiǎn)單的辦法:
在domain包里面定義一個(gè)basedomain類(lèi):
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;
}
}
包含兩個(gè)成員變量
start: 取數(shù)據(jù)時(shí)的起始位置
end: 取數(shù)據(jù)時(shí)的結(jié)束位置
然后各個(gè)實(shí)體類(lèi)將繼承這個(gè)basedomain類(lèi)
然后在要分頁(yè)的sql語(yǔ)句里面加上三層鉗套的sql語(yǔ)句,兩個(gè)rownum參數(shù)分別就是上面的start和end。
以下是一個(gè)示例:
select * from (select my_table.*,rownum as my_rownum from (
select name,password from user? order by id desc
=#start# ]]>
這就是我的ibatis分頁(yè)的辦法,不知道大家覺(jué)得如何?呵呵!
br />我的msn:luyongfugx@hotmail.com