如何在SpringBoot中使用Mybatis分页插件

发布时间:2021-03-23 16:11:32 作者:Leah
来源:亿速云 阅读:181

这篇文章给大家介绍如何在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的调用,直接看调用结果

如何在SpringBoot中使用Mybatis分页插件

如何在SpringBoot中使用Mybatis分页插件

关于如何在SpringBoot中使用Mybatis分页插件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. Mybatis分页插件测试项目
  2. mybatis分页插件MicroPageInterceptor

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot mybatis

上一篇:怎么在python中利用Matplotlib改变坐标轴的默认位置

下一篇:belongsTo怎么在laravel中使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》