mybatis分頁的三種方案

2021-07-14 15:59:03 字數 1325 閱讀 8032

第1種(推薦):看到dao層方法就知道該傳什麼樣的引數,比較直觀

dao層介面函式:

public listgetuserarticles(@param(value="id") int id,@param(value="offset") int offset,@param(value="pagesize") int pagesize);

select

user.id,user.username,user.useraddress,article.id

aid,article.title,article.content from user,article

where

user.id=article.userid and user.id=# limit

#,#

service層呼叫

第2種:

dao層介面函式:

public listgetuserarticles2(int id,int offset,int pagesize);

select

user.id,user.username,user.useraddress,article.id

aid,article.title,article.content from user,article

where

user.id=article.userid and user.id=# limit #,#

service層呼叫

第3種:使用map傳參

dao層介面函式:

public listgetuserarticles3(mapmap);

select

user.id,user.username,user.useraddress,article.id

aid,article.title,article.content from user,article

where

user.id=article.userid and user.id=# limit

#,#

service層呼叫

mapparams =  new hashmap(); 

params.put("id", "1");

params.put("offset", "0");

params.put("pagesize", "2");

SQL三種分頁方案

b 分頁方法 b sql法 儲過程法 游標法。游標耗資 效率低 儲存過程不錯,因為儲存過程是經過預編譯的效率高 靈活。b 這裡介紹sql分頁法 b 方法1 適用於 sql server 2000 2005 select top 頁大小 from table1 where id not in sele...

三種分頁方式

1.分頁方案一 利用not in和select top分頁 語句形式 selecttop10 fromtesttablewhere idnotin selecttop20id fromtesttable orderbyid orderbyidselecttop頁大小 fromtesttablewhe...

Mybatis傳多個引數(三種解決方案)

據我目前接觸到的傳多個引數的方案有三種。dao層的函式方法 public user selectuser string name,string area select from user user t where user name and user area 其中,代表接收的是dao層中的第乙個引...