pagehelper外掛程式,踩坑筆記

2021-10-08 07:51:59 字數 3672 閱讀 8379

在使用過程中,pagehelper外掛程式在複雜的sql查詢count時,會自動生成select count(0) from (需要分頁的sql) tmp_count,有時也會把排序字段放進去,導致count查詢時間很長。

如,生成的分頁sql:

select t.*,

( select x.name from tb_jd_token x where ( x.id = t.mall_flag ) ) as mall_name,

( select `name` from tmk_mall_category tmc where t.category = tmc.id ) as category_name,

case

when (select count(1)

from tmk_good_type a

where t.gdty_id = a.id

and t.status = 1

and a.maca_id in (select x.id from tmk_mall_category x where x.status = 1)

and t.good_count_descn != '無貨'

and t.show_flag in (0, 1, 2)

and t.preferential_price is not null) > 0 then

'已顯示'

else

'未顯示'

end show_count_mean,

concat(

if(t.update_flag = 1, '類目對應關係不存在、', ''),

if(t.update_flag = 2, '該類目無許可權維護、', ''),

if(t.show_flag = 3, '已暫停、', ''),

if((t.preferential_price is null or t.preferential_price = 0), '採購價為空或為0、', ''),

if(t.preferential_price > t.sale_price, '採購價大於官網價、', ''),

if(t.good_count_descn = '無貨', '無貨、', ''),

if(t.status = 0, '已下架、', '')

) not_show_type_mean

from tmk_goods t

order by t.ldate desc

limit ?

自動生成的count查詢語句:

select

count( 0 )

from

(select t.*,

( select x.name from tb_jd_token x where ( x.id = t.mall_flag ) ) as mall_name,

( select `name` from tmk_mall_category tmc where t.category = tmc.id ) as category_name,

case

when (select count(1)

from tmk_good_type a

where t.gdty_id = a.id

and t.status = 1

and a.maca_id in (select x.id from tmk_mall_category x where x.status = 1)

and t.good_count_descn != '無貨'

and t.show_flag in (0, 1, 2)

and t.preferential_price is not null) > 0 then

'已顯示'

else

'未顯示'

end show_count_mean,

concat(

if(t.update_flag = 1, '類目對應關係不存在、', ''),

if(t.update_flag = 2, '該類目無許可權維護、', ''),

if(t.show_flag = 3, '已暫停、', ''),

if((t.preferential_price is null or t.preferential_price = 0), '採購價為空或為0、', ''),

if(t.preferential_price > t.sale_price, '採購價大於官網價、', ''),

if(t.good_count_descn = '無貨', '無貨、', ''),

if(t.status = 0, '已下架、', '')

) not_show_type_mean

from tmk_goods t

order by

t.ldate desc

) tmp_count

原本應該自動生成的count查詢語句:

select count(0) from tmk_goods t
解決方法:

複雜sql分頁時,手寫count查詢語句

手寫的count的sql的statementid = 需要分頁的sql的statementid + 「_count」

pagehelper以「_count」結尾作為count的sql的標誌

resulthandler resulthandler, boundsql boundsql) throws sqlexception else

count = executorutil.executeautocount(this.dialect, executor, countms, parameter, boundsql, rowbounds,

resulthandler);

}return count;

}pagehelper首先判斷有沒有手寫的count語句,沒有的話,就自動生成

例項:tmkgoodsserviceimpl分頁**:

@override

public pageinfofindpage(mapparams)

if (params.get("pagesize") == null)

//分頁外掛程式,第幾頁,每頁顯示數量

pagehelper.startpage(integer.valueof(params.get("pagenumber").tostring()),

integer.valueof(params.get("pagesize").tostring()));

query query = new query(params);

return new pageinfo(tmkgoods);

}

select count(1) from tmk_goods t

int find_count(object object);
count查詢已經變更:

select count(1) from tmk_goods t
附上大致的流程圖:

CSS position sticky 踩坑筆記

在二次開發主題的過程中,發現了很多問題。其中技術點不高,但讓人瞬gan 的就是這一條css屬性。position sticky是css定位新增屬性 可以說是相對定位relative和固定定位fixed的結合 它主要用在對scroll事件的監聽上 簡單來說,在滑動過程中,某個元素距離其父元素的距離達到...

pdfjs dist外掛程式的踩坑

新入職的一家公司,一開始去要求要改乙個bug,是關於pdf檔案上傳的問題。專案中用到了pdfjs dist外掛程式。bug是這樣的,檔案獲取不到。一開始是在頁面中引用 import pdfjs from pdfjs dist import pdfworker from pdfjs dist buil...

使用PageHelper踩的乙個小坑

之前使用pagehelper都沒有問題,今天使用時發現查詢出來的資料沒有分頁。一開始的 時這樣的 public pageinfonotsaleorder integer pageno,integer clientid 問題 pagehelper.startpage pageno,3 應該放在你要分頁...