分页插件Mybatis

xml 复制代码
    <plugins>
        <!-- com.github.pagehelper为PageHelper类所在包名 -->
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <!-- 配置方言:告诉分页插件使用底层数据库是什么-->
            <property name="helperDialect" value="mysql"/>
            <!-- 配置合理化参数:上一页和最后一页 不做加减操作,始终咨询第一页和最后一页-->
            <property name="reasonable" value="true"/>
        </plugin>
    </plugins>



 <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.2.0</version>
        </dependency>
java 复制代码
@Test
public void test(){
    SqlSession sqlSession = MyBatisUtils.getSqlSession();
    BookMapper mapper = sqlSession.getMapper(BookMapper.class);
    //分页
    PageHelper.startPage(2,5);
    List<Book> byPage = mapper.findByPage();
    //分页对象,里面有各种上一页,下一页,总页数,什么的数据
    PageInfo<Book> pageInfo = new PageInfo<>(byPage);
    for (Book book : byPage) {
        System.out.println(book);
    }

    System.out.println("---------------");
    System.out.println(pageInfo);
    System.out.println(pageInfo.getList());

}
相关推荐
C+-C资深大佬18 小时前
SSM 框架(Spring + SpringMVC + MyBatis)
java·spring·mybatis
二王一个今21 小时前
springboot security 权限控制---循环依赖问题
mybatis
落木萧萧8251 天前
为什么我把 MyBatisGX 设计成现在这样
mybatis·orm
代码旅人ing1 天前
Redis+Spring+MyBatis + 微服务 + 消息队列核心知识点(面试高频题目合集)
redis·spring·mybatis·java-rabbitmq
Devin~Y1 天前
大厂Java面试实录:Spring Boot/Cloud、Kafka、Redis、K8s 可观测性 + RAG/Agent(小Y翻车版)
java·spring boot·redis·spring cloud·kafka·kubernetes·mybatis
ppandss11 天前
JavaWeb从0到1-DAY11-MyBatis入门
java·tomcat·mybatis
JAVA面经实录9172 天前
MyBatis面试题库
java·mybatis
杨运交2 天前
[022][数据模块]基于雪花算法的 MyBatis-Plus 主键生成器设计与实现
mybatis
Mahir082 天前
MyBatis 深度解密:从执行流程到底层原理全解
java·后端·面试·mybatis
Mahir082 天前
MyBatis 分页与插件深度解密:从插件机制到三大分页方案原理全解
java·后端·mybatis·mybatis-plus·大厂面试题