0


SpringBoot使用Mybatis-Plus中分页出现total=0的情况解决

在使用Mybatis-Plus进行分页时,发现获取的数据总数total=0,这种里有里有两个值得注意的地方:
一、需要对分页进行配置:
二、目前对于Mybatis-Plus中分页配置出现了改变,高版本和低版本的配置不同:
1.低版本:

@ConfigurationpublicclassMybatisConfig{@BeanpublicPaginationInterceptorpaginationInterceptor(){returnnewPaginationInterceptor();}}

2.高版本:

@BeanpublicMybatisPlusInterceptormybatisPlusInterceptor(){MybatisPlusInterceptor interceptor =newMybatisPlusInterceptor();
    interceptor.addInnerInterceptor(newPaginationInnerInterceptor(DbType.H2));return interceptor;}

分页接口示例:

@GetMapping("/pages/{page}/{size}")publicResultVopageNa(@PathVariable("page")int page,@PathVariable("size")int size){//1.创建page对象//调用方法时候,底层封装,把分页所有数据封装到navigationPage对象里面Page<Navigation> navigationPage =newPage<>(page, size);
        navigationMapper.selectPage(navigationPage,null);System.out.println(navigationPage.getTotal());System.out.println(navigationPage.getRecords());Map<String,Object> map =newHashMap<>(16);

        map.put("total", navigationPage.getTotal());
        map.put("rows", navigationPage.getRecords());returnResultVo.ok().data(map);}

本文转载自: https://blog.csdn.net/weixin_52100990/article/details/134271219
版权归原作者 莽夫三拳有点疼 所有, 如有侵权,请联系我们删除。

“SpringBoot使用Mybatis-Plus中分页出现total=0的情况解决”的评论:

还没有评论