springboot 分页

bookDao.selectPage(null,null);

进入selectPage 里面
在这里插入图片描述
第一个null 需要加入 Ipage类型的
在这里插入图片描述
进入IPage
ctrl + h 查看继承关系
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
加入参数
第一页显示五条数据

在这里插入图片描述

分页如果要使用 必须要使用mp 提供的拦截器

创建一个拦截器的类

package com.itheima.config;

import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MPConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); //  拦截器的壳 没有拦截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());// 添加內部分页拦截器
        
        return interceptor;
    }
}


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


  void testGetPage(){
        IPage iPage = new Page(2,5);
        bookDao.selectPage(iPage,null);
        System.out.println(iPage.getCurrent()); // 当前页
        System.out.println(iPage.getSize());// 一页显示多少数据
        System.out.println(iPage.getTotal());// 一共多少数据
        System.out.println(iPage.getPages());// 一共能分多少页
        System.out.println(iPage.getRecords());// 当前页的数据
    }
 @Test
    void testgetBy(){
        QueryWrapper<Book> queryWrapper = new QueryWrapper(); // 条件的壳
        queryWrapper.like("name","spring"); //查询 name 值中包含spring的数据
        bookDao.selectList(queryWrapper);
    }

在这里插入图片描述
该方法 如果name 属性值 写错 比如写成 anme 那么就会报错
在这里插入图片描述
可以改成LambdaQueryWrapper

   @Test
    void testgetBy2(){
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper(); // 条件的壳
        lqw.like(Book::getName,"spring");
        bookDao.selectList(lqw);
    }

如果查询结果是null 则 会将null 当成字符串查询

   String name = null;
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper(); // 条件的壳
        lqw.like(Book::getName,name);
        bookDao.selectList(lqw);

在这里插入图片描述
在这里插入图片描述
有一个condition 条件 如果是true 就连 如果是false 就不连后面的查询条件
在这里插入图片描述
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值