日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

SpringBoot使用Mybatis-Plus中分頁出現(xiàn)total=0的情況解決

作者:莽夫三拳有點(diǎn)疼 更新時(shí)間: 2024-04-08 編程語言

在使用Mybatis-Plus進(jìn)行分頁時(shí),發(fā)現(xiàn)獲取的數(shù)據(jù)總數(shù)total=0,這種里有里有兩個(gè)值得注意的地方:
一、需要對(duì)分頁進(jìn)行配置:
二、目前對(duì)于Mybatis-Plus中分頁配置出現(xiàn)了改變,高版本和低版本的配置不同:
1.低版本:

@Configuration
public class MybatisConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}

2.高版本:

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
    return interceptor;
}

分頁接口示例:

  @GetMapping("/pages/{page}/{size}")
    public ResultVo pageNa(@PathVariable("page") int page,
                           @PathVariable("size") int size) {

        //1.創(chuàng)建page對(duì)象
        //調(diào)用方法時(shí)候,底層封裝,把分頁所有數(shù)據(jù)封裝到navigationPage對(duì)象里面
        Page<Navigation> navigationPage = new Page<>(page, size);
        navigationMapper.selectPage(navigationPage, null);
        System.out.println(navigationPage.getTotal());
        System.out.println(navigationPage.getRecords());
        Map<String, Object> map = new HashMap<>(16);

        map.put("total", navigationPage.getTotal());
        map.put("rows", navigationPage.getRecords());

        return ResultVo.ok().data(map);
    }

原文鏈接:https://blog.csdn.net/weixin_52100990/article/details/134271219

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新