MybatisPlus中selectPage的使用方法
更新時間:2023年05月29日 11:12:24 作者:Archie_java
本文主要介紹了MybatisPlus中selectPage的使用方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
方法說明
代碼如下(示例):
// 根據(jù) entity 條件,查詢?nèi)坑涗洠ú⒎摚? IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
參數(shù)說明
參數(shù)名 | 描述 |
---|---|
page | 分頁查詢條件(可以為 RowBounds.DEFAULT) |
queryWrapper | 實體對象封裝操作類(可以為 null) |
沒mybatisPlus坐標的可以導(dǎo)一下
<!--mybatis-plus的springboot支持--> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.2.0</version> </dependency>
selectPage的方法定義
/*** 根據(jù) entity 條件,查詢?nèi)坑涗洠ú⒎摚? ** @param page 分頁查詢條件(可以為 RowBounds.DEFAULT) * @param queryWrapper 實體對象封裝操作類(可以為 null) * */ * IPage<T> selectPage(IPage<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
配置分頁插件:
@Configuration @MapperScan("cn.itcast.mp.mapper") ?//設(shè)置mapper接口的掃描 public class MybatisPlusPage { ? ? @Bean ? ? public PaginationInterceptor paginationInterceptor(){ ? ? ? ? return new ?PaginationInterceptor(); ? ? } }
測試:
?? ?@Test ? ? public void selectPage(){ ? ? ? ? Page<User> page = new Page<>(1,2); ? ? ? ? QueryWrapper<User> wrapper = new QueryWrapper<>(); ? ? ? ? wrapper.ge("age",20); ? ? ? ? IPage<User> iPage = userMapper.selectPage(page, wrapper);?? ?//Preparing: SELECT COUNT(1) FROM tb_user WHERE (age >= ?)? ? ? ? ? List<User> records = iPage.getRecords(); ? ? ? ? for (User record : records) { ? ? ? ? ? ? System.out.println(record); ? ? ? ? } ? ? ? ? System.out.println("當前頁"+iPage.getCurrent()); ? ? ? ? System.out.println("總頁數(shù)"+iPage.getPages()); ? ? ? ? System.out.println("總記錄數(shù)"+iPage.getTotal()); ? ? ? ? System.out.println("每頁顯示條數(shù)"+iPage.getSize()); ? ? }
到此這篇關(guān)于MybatisPlus中selectPage的使用方法的文章就介紹到這了,更多相關(guān)MybatisPlus selectPage內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringMVC中使用bean來接收form表單提交的參數(shù)時的注意點
本篇文章主要介紹了SpringMVC中使用bean來接收form表單提交的參數(shù)時的注意點,具有很好的參考價值。下面跟著小編一起來看下吧2017-05-05jdk8?FunctionalInterface注解源碼解讀
這篇文章主要介紹了jdk8?FunctionalInterface注解源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11IntelliJ IDEA2019 安裝lombok的實現(xiàn)
這篇文章主要介紹了IntelliJ IDEA2019 安裝lombok的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10