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

}
相关推荐
creator_Li19 小时前
手写Redis系列:二、简单动态字符串SDS
数据库·redis·mybatis
z***33520 小时前
SpringCloud 系列教程:微服务的未来(二)Mybatis-Plus的条件构造器、自定义SQL、Service接口基本用法
spring cloud·微服务·mybatis
R***62311 天前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis
梅梅绵绵冰1 天前
ssm整合框架
数据库·mybatis
nbsaas-boot1 天前
JPA vs MyBatis 在大型 SaaS 架构中的使用边界
spring·架构·mybatis
i***66501 天前
Spring-boot3.4最新版整合swagger和Mybatis-plus
mybatis
k***81722 天前
IDEA搭建SpringBoot,MyBatis,Mysql工程项目
spring boot·intellij-idea·mybatis
好好研究2 天前
MyBatis框架 - 注解形式
java·数据库·mysql·maven·mybatis
l***37092 天前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
Dreamboat-L2 天前
MyBatis-Plus 核心注解详解:让你告别繁琐配置
mybatis