分页插件PageHelper的安装,使用

 安装:

pom文件

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.6</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

传统使用:

pagebean 是封装类,一个是总数,一个是数据

 插件

/**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Activity activity,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Activity> page = activityService.selectPage(activity, pageNum, pageSize);
        return Result.success(page);
    }
/**
     * 分页查询
     */
    public PageInfo<Activity> selectPage(Activity activity, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Activity> list = activityMapper.selectAll(activity);
        return PageInfo.of(list);
    }
<select id="selectAll" resultType="com.example.entity.Activity">
        select
        <include refid="Base_Column_List" />
        from activity
        <where>
            <if test="id != null"> and id = #{id}</if>
            <if test="name != null"> and name like concat('%', #{name}, '%')</if>
            <if test="descr != null"> and descr like concat('%', #{descr}, '%')</if>
            <if test="start != null"> and start like concat('%', #{start}, '%')</if>
            <if test="end != null"> and end like concat('%', #{end}, '%')</if>
            <if test="form != null"> and form like concat('%', #{form}, '%')</if>
            <if test="address != null"> and address like concat('%', #{address}, '%')</if>
            <if test="host != null"> and host like concat('%', #{host}, '%')</if>
            <if test="readCount != null"> and read_count = #{readCount}</if>
            <if test="cover != null"> and cover = #{cover}</if>
        </where>
        order by id desc
    </select>

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值