java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > SpringBoot Mybatis分页插件

SpringBoot 使用Mybatis分页插件实现详解

作者:lcl-mm

这篇文章主要介绍了SpringBoot 使用Mybatis分页插件实现详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

这篇文章主要介绍了SpringBoot 使用Mybatis分页插件实现详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

1、导入分页插件包和jpa包

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper-spring-boot-starter</artifactId>
      <version>1.2.5</version>
    </dependency>

2、增加分页配置

# 主键自增回写方法,默认值MYSQL,详细说明请看文档
mapper:
 identity: MYSQL
# 设置 insert 和 update 中,是否判断字符串类型!=''
 not-empty: true
# 枚举按简单类型处理
 enum-as-simple-type: true
######### 分页插件 ##########
pagehelper:
 helper-dialect: mysql
 params:
  count: countSql
 reasonable: false
 support-methods-arguments: true

配置说明:

3、使用插件进行分页查询

  public PageInfo<User> selectByUsername(String username,int limit, int page){
    PageHelper.startPage(page, limit).setOrderBy("id desc");
    PageInfo<User> userPageInfo = new PageInfo<>(this.userMapper.selectByuserName(username));
    return userPageInfo;
  }

4、测试

此处不在写Controller类及中间Service的调用,直接看调用结果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文