欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mybatis-Plus分頁(yè)的使用與注意事項(xiàng)

 更新時(shí)間:2022年04月22日 15:24:52   作者:為了我的架構(gòu)師  
分頁(yè)查詢每個(gè)人程序猿幾乎都使用過(guò),下面這篇文章主要給大家介紹了關(guān)于Mybatis-Plus分頁(yè)的使用與注意事項(xiàng)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

1.寫(xiě)個(gè)Mybatis-plus配置類:

是通過(guò)攔截器實(shí)現(xiàn)分頁(yè)

@Configuration
public class MybatisConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

官網(wǎng)復(fù)制即可,只是你需要把數(shù)據(jù)庫(kù)改為你使用的,這里我是使用mysql

image-20211127103508187

2.寫(xiě)接口測(cè)試

很簡(jiǎn)單

@GetMapping("/test")
    public Response test(){
        Page<Produce> producePage = new Page<>(1,1);
        Page<Produce> page = produceService.page(producePage);
        System.out.println(producePage == page);
        List<Produce> records = page.getRecords();
        for (Produce record : records) {
            System.out.println(record);
        }
        return new Response<>(records, ResultEnum.SUCCESS);
    }

image-20211127104035078

默認(rèn)是會(huì)查詢總條數(shù),都有g(shù)et、set方法,可以根據(jù)自己的需求設(shè)置(點(diǎn)開(kāi)Page類看看)

image-20211127113428364

3.注意

我們傳入的page對(duì)象和查詢返回的page對(duì)象是同一個(gè)

image-20211127105657392

image-20211127105710551

4.如果你還有查詢條件

比如我們只查詢id和price,id小于5的分頁(yè)查詢

image-20211127112433085

1.Lambda表達(dá)式

@GetMapping("/test")
public Response test(){
    Page<Produce> producePage = new Page<>(1,2);
    Page<Produce> page = new LambdaQueryChainWrapper<>(produceService.getBaseMapper())
            .select(Produce::getPid,Produce::getPrice)
            .lt(Produce::getPid,5)
            .page(producePage);

    return new Response<>(page.getRecords(), ResultEnum.SUCCESS);
}

image-20211127112546762

2.普通查詢

@GetMapping("/test")
public Response test(){
    Page<Produce> producePage = new Page<>(1,2);
    QueryWrapper<Produce> queryWrapper = new QueryWrapper<>();
    queryWrapper.select("pid","price");
    queryWrapper.lt("pid",5);
    Page<Produce> page = produceService.page(producePage, queryWrapper);
    return new Response<>(page.getRecords(), ResultEnum.SUCCESS);
}

image-20211127113153795

image-20211127113105586

總結(jié)

到此這篇關(guān)于Mybatis-Plus分頁(yè)的使用與注意事項(xiàng)的文章就介紹到這了,更多相關(guān)Mybatis-Plus分頁(yè)使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論