MyBatis Plus 分頁 排序聯合使用

2021-09-28 11:34:03 字數 2186 閱讀 5323

其實兩者聯合使用非常簡單,只需要在使用分頁外掛程式的基礎上使用其提供的orderbydesc/orderbyasc就能完美融合。寫這篇部落格只是給一些初學者乙個方便的整理而已。下面會先給出完整的使用情況,在到後面分別解釋兩者的用法。以方便只關心這個用法或者趕時間的朋友。處於保密性考慮,我將大部分字段進行了刪減,將專案名也進行了修改

@slf4j

@validated

@restcontroller

public class comorganizationcontroller

//如果前端有值傳入 則將其賦值。無則就不賦值。為後面設定查詢條件鋪路

//設定查詢條件

//根據id進行順序排序 id可用替換為你想進行排序的字段

//將頁碼與每頁展示數量傳入

ipagepage = new page<>(long.parselong(param.getpagenumber()), long.parselong(param.getpagesize()));

//第三個欄位為快取設定的key值

}}

public inte***ce comorganizationservice extends iservice
//專案使用redis快取 自定義key值 這樣能保證唯一,方便使用且易於檢視

@cacheable(cachenames = "comorganization", key = "#root.targetclass.******name+':'+#root.methodname+':'+#key")

@override

return response.data(popage);

}

/**

* * 租戶機構表

* *

* @author campchen

* @since 2019-04-28

*/@data

@equalsandhashcode(callsuper = false)

@accessors(chain = true)

@tablename("com_organization")

public class comorganization implements serializable

/**

* * 查詢租戶機構表引數

* *

* @author campchen

* @since 2019-04-28

*/@data

@equalsandhashcode(callsuper = false)

public class comorganizationqueryparam extends commonparam

@data

public abstract class commonparam implements serializable

/**

* *

* @author campchen

* @since 2019-04-28

*/}

<?xml version="1.0" encoding="utf-8"?>
至此 就完成了整個mybatisplus 的分頁排序的**。其提供了強大的功能,不需要我們再去編寫其餘**。

分頁外掛程式沒有比官網介紹更清楚的了。那邊清楚的講述了來龍去脈。

orderbyasc(r... columns)

orderbyasc(boolean condition, r... columns)

例: orderbyasc("id", "name")--->order by id asc,name asc

orderbydesc(r... columns)

orderbydesc(boolean condition, r... columns)

例: orderbydesc("id", "name")--->order by id desc,name desc

好長一段時間沒有寫部落格了,一方面忙,一方面也沒有碰到什麼需要解決的困難。這裡是做為乙個新手上手mybatisplus的一些記錄。作為乙個成長的記錄把。加油!!!

MyBatis Plus 分頁 排序聯合使用

其實兩者聯合使用非常簡單,只需要在使用分頁外掛程式的基礎上使用其提供的orderbydesc orderbyasc就能完美融合。寫這篇部落格只是給一些初學者乙個方便的整理而已。下面會先給出完整的使用情況,在到後面分別解釋兩者的用法。以方便只關心這個用法或者趕時間的朋友。處於保密性考慮,我將大部分字段...

mybatis plus分頁步驟

控制器層 需要傳入兩個引數page 當前頁數 limit 每頁數量 獲取分頁資料 page page1 new page page,limit page1 noticeservice.getpagenotice page1 listnotices page1.getrecords 介面 pagege...

MyBatis Plus 分頁查詢

文章目錄 1.建立分頁外掛程式 2.測試分頁 3.自定義分頁 4.測試自定義分頁方法 5.控制台輸出 6.多表操作 1.建立分頁外掛程式 configuration public class mybatisplusconfig 總頁數 總記錄數 pagepage new page 1,2 syste...