springboot集成pageHelper做分页

1.mybatis分页插件pageHelper,有了它我们就不用去在意,mysql分页如何写,oralce分页如何写了,使用很方便

2.添加maven依赖

  <!-- mybatis依赖 -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!-- springboot Jdbc支持 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

 <!-- springboot分页插件 -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <!-- 特别注意版本问题, 看到评论以后得以纠正 -->
            <version>1.2.3</version>
        </dependency>

3.通过PageHelper.startPage(pageNo,pageSize); 传入页号 和页的大小 在执行sql语句即可,然后通过PageInfo获取分页详细信息

注:Pagination  -》自己封装的一个分页实体

    PageHelper.startPage(pageNo,pageSize);
    List<User> users = userMapper.selectByExample(example);
    PageInfo<User> pageInfo = new PageInfo<>(users);
    pagination.setPageNo(pageNo);
    pagination.setPageSize(pageSize);
    pagination.setTotalCount((int) pageInfo.getTotal());
    pagination.setList(users);

猜你喜欢

转载自blog.csdn.net/qq_41975950/article/details/86491184
今日推荐