springboot集成pagehelper分页插件

之前写的项目都是在前端进行分页,最近涉及到后台分页查询,回看自己之前练习的项目里发现自己写了分页给忘了,作为初级程序员拿来记录一下

引入pagehelper的pom依赖

    <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.0</version>
        </dependency>

书写pagehelper的配置类

/**
 * mybatis分页插件配置
 * @author xWang
 * @Date 2019-07-12
 */
@Configuration
public class MyBatisConfig {
    @Bean
    public PageHelper pageHelper(){
        PageHelper pageHelper = new PageHelper();
        Properties p = new Properties();
        p.setProperty("offsetAsPageNum","true");
        p.setProperty("rowBoundsWithCount","true");
        p.setProperty("reasonable","true");
        pageHelper.setProperties(p);
        return pageHelper;
    }
}

mapper层

  @Select("select * from video")
    List<Video> findAll();

service层没东西就不贴了,根据实际需要书写

controller层

  @GetMapping("/page")
    public Object findAll(@RequestParam(value = "page",defaultValue = "1")int page,
                          @RequestParam(value = "size",defaultValue = "10")int size){
        PageHelper.startPage(page, size);//分页
        List<Video> list = videoService.findAll();
        PageInfo<Video> pageInfo = new PageInfo<Video>(list);
        Map<String,Object>data=new HashMap<>();//装载分页数据
        data.put("toatl_page",pageInfo.getTotal());//总条数
        data.put("toatl_size",pageInfo.getPages());//总页数
        data.put("currrent_page",page);//当前页
        data.put("toatl_page",pageInfo.getList());//数据
        return data;
    }

这里需要注意传参调用pagehelper的方法语句

     PageHelper.startPage(page, size);//分页
        List<Video> list = videoService.findAll();
        PageInfo<Video> pageInfo = new PageInfo<Video>(list);

致此,分页查询书写完成,步骤还是比较简单的,作为知识点记录一下,同时加深下印象,免得自己又忘了,哈哈

原文地址:https://www.cnblogs.com/xiaowangxiao/p/11334466.html

时间: 2024-07-29 19:48:41

springboot集成pagehelper分页插件的相关文章

SpringBoot整合Pagehelper分页插件

在web开发中,数据的分页是必不可少的.Pagehelper分页插件很强大,虽说平时我们不需要用到它的很多功能,但是了解下还是有必要的. 官网:https://pagehelper.github.io/ 注:在 MyBatis下使用. 一.Pagehelper分页插件介绍 原文地址:https://www.cnblogs.com/myitnews/p/12349655.html

SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了.全部自动实现. 话不多说,直接上代码: 第一步pom文件配置添加jar: <!-- mybatis的分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>

springboot + mybatis配置分页插件

1:首先配置springboot +mybatis框架  参考:http://www.cnblogs.com/liyafei/p/7911549.html 2:创建配置类MybatisConfig,对分页插件进行配置.将mybatis-config.xml移动到classpath路径下. package com.liyafei.util.pagehelper; import java.util.Properties; import org.apache.ibatis.plugin.Interce

逆向工程文件example完美结合使用PageHelper分页插件及分页不成功原因

原生的mybatis需要手写sql语句,项目数据库表多了之后,可以让你写sql语句写到手软,于是mybatis官方提供了mybatis-generator:mybatis逆向工程代码生成工具,用于简化mybatis单表操作. 在PageHelper3.几的版本的时候,使用它对逆向工程生成的查询方法进行分页时出现失效的情况,而PageHelper4开始,亲测能够与mybatis逆向工程生成的方法完美兼容,今天就和大家分享spring+springmvc+mybatis+PageHelper的项目遇

小白的springboot之路(十五)、mybatis的PageHelper分页插件使用

0.前言 用mybatis,那么分页必不可少,基本都是用PageHelper这个分页插件,好用方便: 1.实现 1.1.添加依赖: <!-- 3.集成 mybatis pagehelper--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version

springboot使用Mybatis分页插件

springboot整合mybatis可以使用springboot配置文件的形式,但是配置不了mybatis-config.xml文件(能够配置,但是不扫描),因此数据源和mybatis使用bean的形式处理,实现分页. 一.添加数据源bean,代码如下 package tjresearch; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.support.http.StatViewServlet;

PageHelper分页插件及通用分页js

 分页概述 1.物理分页 物理分页依赖的是某一物理实体,这个物理实体就是数据库,比如MySQL数据库提供了limit关键字,程序员只需要编写带有limit关键字的SQL语句,数据库返回的就是分页结果.建议使用. 2.逻辑分页 逻辑分页依赖的是程序员编写的代码.数据库返回的不是分页结果,而是全部数据,然后再由程序员通过代码获取分页数据,常用的操作是一次性从数据库中查询出全部数据并存储到List集合中,因为List集合有序,再根据索引获取指定范围的数据. MyBatis 分页插件 - PageHel

pageHelper分页插件使用总结

1.添加jar包货添加pom文件 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.0.0</version> </dependency>2.添加插件配置在mybatis-config配置文件中添加插件<configuration> <!--

mybatis逆向工程带条件查询用PageHelper分页插件出错

问题: There is no getter for property named '__frch_criterion_1' in 'class com.××.××.TbContentExample'.可是我并没有定义这个变量. 代码如下: //执行查询 TbContentExample example = new TbContentExample(); Criteria criteria = example.createCriteria(); criteria.andCategoryIdEqu