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

}
相关推荐
2601_9498177210 小时前
Spring Boot3.3.X整合Mybatis-Plus
spring boot·后端·mybatis
LaLaLa_OvO17 小时前
mybatis 引用静态常量
java·mybatis
yaodong51817 小时前
Spring 中使用Mybatis,超详细
spring·tomcat·mybatis
2601_9498153319 小时前
Spring Boot中集成MyBatis操作数据库详细教程
数据库·spring boot·mybatis
星晨雪海19 小时前
若依框架原有页面功能进行了点位管理改造之列表查询(4)
数据库·sql·mybatis
mldlds20 小时前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis
那个失眠的夜1 天前
Spring整合Mybatis实现用户的CRUD
java·spring·mybatis
zjjsctcdl1 天前
Spring Boot 整合 MyBatis 与 PostgreSQL 实战指南
spring boot·postgresql·mybatis
zmsofts1 天前
java面试必问13:MyBatis 一级缓存、二级缓存:从原理到脏数据,一篇讲透
java·面试·mybatis
MegaDataFlowers2 天前
使用SpringBoot+MyBatis+MySQL完成后端的数据库增删改查(CRUD)操作
数据库·spring boot·mybatis