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

}
相关推荐
j***121510 小时前
Spring Boot与MyBatis
spring boot·后端·mybatis
java1234_小锋16 小时前
简述Mybatis的插件运行原理?
java·开发语言·mybatis
z***67771 天前
SpringBoot(整合MyBatis + MyBatis-Plus + MyBatisX插件使用)
spring boot·tomcat·mybatis
b***67641 天前
Springboot3 Mybatis-plus 3.5.9
数据库·oracle·mybatis
k***1951 天前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
e***74952 天前
SpringCloud 系列教程:微服务的未来(二)Mybatis-Plus的条件构造器、自定义SQL、Service接口基本用法
spring cloud·微服务·mybatis
chxii2 天前
在 Spring Boot 中,MyBatis 的“自动提交”行为解析
java·数据库·mybatis
有一个好名字2 天前
MyBatis-Plus 三种数据库操作方式详解 + 常用方法大全
数据库·mybatis
颜如玉2 天前
动态拼接SQL实践备忘📝
java·sql·mybatis
朝新_3 天前
【实战】博客系统:项目公共模块 + 博客列表的实现
数据库·笔记·sql·mybatis·交互·javaee