Mybatis Plus 分頁插件

1. 在config文件里面新增分頁插件

//分頁插件
@Bean
public PaginationInterceptor paginationInterceptor() {
    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
    // 設(shè)置請(qǐng)求的頁面大于最大頁后操作, true調(diào)回到首頁,false 繼續(xù)請(qǐng)求  默認(rèn)false
    // paginationInterceptor.setOverflow(false);
    // 設(shè)置最大單頁限制數(shù)量,默認(rèn) 500 條,-1 不受限制
    // paginationInterceptor.setLimit(500);
    // 開啟 count 的 join 優(yōu)化,只針對(duì)部分 left join
//        paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
    return paginationInterceptor;
}

2. 在代碼里使用分頁插件

@Test
void testPageQuery(){
    Page<User> page = new Page<>(3,5);
    //wrapper 條件構(gòu)造器,模糊查詢,排序,多表查詢,子查詢等
    userMapper.selectPage(page,null);
    List<User> users = page.getRecords();
    users.forEach(System.out::println);
    System.out.println(page.getCurrent());
    System.out.println(page.getOrders());
    System.out.println(page.getRecords());
    System.out.println(page.getSize());
    System.out.println(page.getTotal());
    System.out.println(page.hasNext());
    System.out.println(page.hasPrevious());

}


@Test
void testPageQuery2(){
    Page<Map<String,Object>> page = new Page<>(3,5);
    //wrapper 條件構(gòu)造器,模糊查詢,排序,多表查詢,子查詢等
    IPage<Map<String,Object>> mapIPage = userMapper.selectMapsPage(page,null);
    mapIPage.getRecords().forEach(System.out::println);
    System.out.println(page.getCurrent());
    System.out.println(page.getOrders());
    System.out.println(page.getRecords());
    System.out.println(page.getSize());
    System.out.println(page.getTotal());
    System.out.println(page.hasNext());
    System.out.println(page.hasPrevious());

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容