Springboot---分页

本文介绍了在SpringBoot中使用SQL分页和PageHelper插件进行分页的方法。针对SQL分页的局限性,提出了利用主键索引进行优化。详细讲述了PageHelper的配置和使用,包括在UserMapper接口、Map.xml文件和UserController中的应用。
摘要由CSDN通过智能技术生成

参考:springboot 中 分页实现SpringBoot分页插件PageHelper

目录

1. sql分页

2. 插件分页-PageHelper

2.1 插件依赖

2.2 配置application.yml文件

2.3 使用

2.3.1 UserMapper接口

2.3.2 Map.xml文件

2.3.3 UserController


1. sql分页

  • 语句样式: MySQL中,可用如下方法: SELECT * FROM 表名称 LIMIT ${offset},${limit}

  • 适应场景: 适用于数据量较少的情况(元组百/千级)

  • 原因/缺点: 全表扫描,速度会很慢 且 有的数据库结果集返回不稳定(如某次返回1,2,3,另外的一次返回2,1,3). Limit限制的是从结果集的M位置处取出N条输出,其余抛弃.

eg:

  <select id="list" resultType="com.sqlb.pojo.Article">
        select
        <include refid="Base_Column_List"/>
        from article
        <where>
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="author != null and author != ''">and author = #{author}</if>
            <if test="createTime != null and createTime != ''">and create_time = #{createTime}</if>
            <if test="typeName != null and typeName != ''">and type_name = #{typeName}</if>
            <if test="imageUrl != null and imageUrl != ''">and image_url = #{imageUrl}</if>
            <if test="content != null and
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值