風人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
          數據加載中……

          ibatis分頁做法(ZT)

          以前用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]]>

          posted on 2006-07-05 17:53 風人園 閱讀(859) 評論(0)  編輯  收藏 所屬分類: Database

          主站蜘蛛池模板: 台北县| 阿鲁科尔沁旗| 枣强县| 庄河市| 汝州市| 东山县| 苗栗市| 德格县| 廊坊市| 平原县| 城口县| 长武县| 渝中区| 汉沽区| 泰州市| 上思县| 耒阳市| 名山县| 丰顺县| 凭祥市| 岳阳市| 建平县| 盐山县| 天全县| 芜湖市| 改则县| 建阳市| 巧家县| 庆云县| 同仁县| 桐庐县| 资阳市| 且末县| 原阳县| 临泽县| 浮山县| 齐河县| 镇安县| 砚山县| 灵山县| 浪卡子县|