栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

记一篇MybatisPlus分页失效解决方案

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

记一篇MybatisPlus分页失效解决方案

刚才使用mybatisplus提供的Page分页时,一直失效,看网上说要加配置什么的,试了多种方案还是不行。最后自己结合github pagehelper实现了分页,目前还不知道有没有其他影响。我使用的是springboot项目,下面就开始编码吧。

一、环境搭建

springboot:2.0.6.RELEASE
mybatis-plus-status:3.4.2
pagehelper:1.3.0

  
        com.longfor.c2
        cmo-expense
        1.0.0-SNAPSHOT
    
        
        
            org.apache.velocity
            velocity-engine-core
            2.2
        

        
            com.baomidou
            mybatis-plus-generator
            3.4.0
        

        
            com.baomidou
            mybatis-plus-boot-starter
            3.4.2
        

        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.3.0
            
                
                    org.mybatis
                    mybatis
                
                
                    org.mybatis
                    mybatis-spring
                
            
        
二、配置类
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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

三、代码示例
 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
 queryWrapper.in(Student::getId, Arrays.asList(ids));
 //输入页码和页数
 PageHelper.startPage(query.getPageNumber(), query.getPageSize());
 List students= studentService.getBaseMapper().selectList(queryWrapper);
 com.github.pagehelper.PageInfo pageInfo = new com.github.pagehelper.PageInfo<>(students);
 //students--分页后的数据 pageInfo.getTotal()--总条数
 return PageResponse.page(students, pageInfo.getTotal()); 
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/921907.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号