分页插件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());

}
相关推荐
期待のcode9 小时前
MyBatis-Plus的Wrapper核心体系
java·数据库·spring boot·后端·mybatis
期待のcode13 小时前
Springboot数据层开发—Springboot整合JdbcTemplate和Mybatis
spring boot·后端·mybatis
在坚持一下我可没意见14 小时前
Spring 开发小白学习过程中常用通用配置文件,即拿即用!(持续更新中)
java·数据库·后端·学习·spring·tomcat·mybatis
m0_7400437314 小时前
SpringBoot03-Mybatis框架入门
java·数据库·spring boot·sql·spring·mybatis
计算机学姐2 天前
基于SSM的生鲜食品商城系统【2026最新】
java·vue.js·后端·mysql·java-ee·tomcat·mybatis
梁bk2 天前
苍穹外卖项目总结(一)[MyBatis-Plus,文件上传,Redis]
数据库·redis·mybatis
小坏讲微服务2 天前
Spring Boot 4.0 + MyBatis-Plus 实战响应式编程的能力实战
java·spring boot·后端·mybatis
缘来是庄2 天前
invalid comparison
java·spring boot·mybatis
小二·2 天前
MyBatis基础入门《十》Spring Boot 整合 MyBatis:从单数据源到多数据源实战
spring boot·后端·mybatis
爱学习的小可爱卢2 天前
JavaEE进阶——MyBatis动态SQL与图书管理系统实战
spring·mybatis