Mybatis之分頁插件PagerHelper使用

Maven增長依賴mysql

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

 

 

Mybatis配置文件分頁插件git

<!-- 配置分頁插件 -->
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageHelper">
            <!-- 設置數據庫類型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種數據庫-->        
            <property name="dialect" value="mysql"/>
        </plugin>
    </plugins>

 

 

Mapper xmlgithub

<select id="pageTest" resultType="com.zns.model.Test">
        select id,name from test
</select>

 

 

Mappersql

public Page<Test> pageTest();

 

 

Service數據庫

public Page<Test> pageTest(){
    PageHelper.startPage(1, 10);
    return testMapper.pageTest();
}

 

 

Controllerapp

public void testPager() {
        Page<Test> pageInfo= testService.pageTest();
        List<Test> list=pageInfo.getResult();
        long totalCount=pageInfo.getTotal();
        for (Test test : list) {
            System.out.println(test.getId()+"--"+test.getName());
            }
        System.out.println(totalCount);
}
相關文章
相關標籤/搜索