spring boot项目中整合mybatisPlus和pageHelper

1 首先导入相关jar包

<!--spring boot整合mybatisPlus和pageHelper-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.3</version>
            <!--这里排除mybatis相关jar包,因为会和mybatisPlus中的mybatis的jar包产生冲突-->
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis-spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--导入mybatis-plus-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.1</version>
        </dependency>

2. 然后就是yml文件修改

mybatis-plus:
  mapper-locations: classpath*:mapper/**.xml
  type-aliases-package: com.etouch.mapper          #  接口包
  #实体扫描,多个package用逗号或者分号分隔
  #  typeAliasesPackage: com.pm.facade.*.entity
  global-config:
    db-config:
      #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
      id-type: auto
      #驼峰下划线转换
      column-underline: true
      #数据库大写下划线转换
      db-type: mysql
      #刷新mapper 调试神器
    refresh: true
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false

pagehelper:
  reasonable: true # 禁用合理化时
  support-methods-arguments: true
  params: count=countSql
  row-bounds-with-count: true
  helper-dialect: mysql

3. 最后测试

3.1 controller层

  @GetMapping("/pageHelper")
    public ResultUtils<UserDTO> test(Integer start,Integer pageSize) {
        PageInfo pageInfo = sysUserService.getPage(start,pageSize);
        return ResultUtils.success(pageInfo);
    }

3.2 service层

    @Override
    public PageInfo<UserDTO> getPage(Integer start, Integer pageSize) {
    //写上下面这一行代码会自动进行分页
        PageHelper.startPage(start, pageSize);
        List<SysUser> sysUserList = userMapper.getPage();
        List<UserDTO> userDTOList = BeanHelper.copyWithCollection(sysUserList, UserDTO.class);
        PageInfo<UserDTO> objectPageInfo = new PageInfo(userDTOList);
        return objectPageInfo;
    }

mapper和xml文件就不贴了, 最简单的单表查询

3.3 运行查看结果

在这里插入图片描述
在这里插入图片描述

3.4 查看控制台输出日志

发现使用pageHelper.start()后, 他会在执行的sql中自动拼接上limit ?,?
这里使用的什么原理不清楚 , 搞清楚了, 再来丰富一下, 现在只做记录
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

意田天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值