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

學無先后,達者為師

網站首頁 編程語言 正文

SpringBoot使用Mybatis-Plus中分頁出現total=0的情況解決

作者:莽夫三拳有點疼 更新時間: 2024-04-08 編程語言

在使用Mybatis-Plus進行分頁時,發現獲取的數據總數total=0,這種里有里有兩個值得注意的地方:
一、需要對分頁進行配置:
二、目前對于Mybatis-Plus中分頁配置出現了改變,高版本和低版本的配置不同:
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.創建page對象
        //調用方法時候,底層封裝,把分頁所有數據封裝到navigationPage對象里面
        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

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