Mybatis之PageHelper分页插件

使用该插件,快速实现查询结果的分页,使用步骤如下

1、pom.xml中导入依赖

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.6</version>
        </dependency>

2、mybatis全局配置文件中配置<plugin>标签

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">


<configuration>

    <properties resource="db.properties"/>

    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
            <property name="helperDialect" value="mysql"/>
        </plugin>
    </plugins>
    
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC">
                <property name="..." value="..."/>
            </transactionManager>
            <dataSource type="POOLED">
                <property name="driver" value="${driver}"/>
                <property name="url" value="${url}"/>
                <property name="username" value="${username}"/>
                <property name="password" value="${password}"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper resource="chen/mapper/StudentMapper.xml"/>
    </mappers>
</configuration>

3、在查询前,先设置分页信息

//查询第一页,每页三条数据
PageHelper.startPage(1,3);

在这里插入图片描述

4、结果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_45151059/article/details/113817235