1. 程式人生 > >SpringBoot2.0整合MyBatis的分頁外掛PageHelper

SpringBoot2.0整合MyBatis的分頁外掛PageHelper

PageHelper是MyBatis的一款分頁外掛,支援常見的 12 種資料庫,如Oracle,MySql,MariaDB,SQLite,DB2,PostgreSQL,SqlServer 等,專案地址:https://github.com/pagehelper/Mybatis-PageHelper

一、配置好MyBatis

二、build.gradle匯入pagehelper的依賴

compile group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: '1.2.7'

三、使用方法

PageHelper的使用十分簡單,只有一行程式碼:
PageHelper.startPage(0,3);//limit 0,3

四、單元測試

一個單元測試demo,注意必須在使用mapper介面進行查詢前,先呼叫分頁外掛進行分頁:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = CoreApplication.class)
@WebAppConfiguration
public class TestPageHelper {
    @Autowired
    private ContentVoMapper contentVoMapper;
    @Test
    public void testPageHelper(){
        PageHelper.
startPage(0,3);//limit 0,3 ContentVoExample ex = new ContentVoExample(); List<ContentVo> contentVos = contentVoMapper.selectByExample(ex); for (ContentVo contentVo : contentVos) { System.out.println(contentVo.getTitle()); } } }

分頁成功,顯示前三條資料:
在這裡插入圖片描述

相關推薦

SpringBoot整合MyBatis外掛PageHelper

原創作品,可以轉載,但是請標註出處地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分頁外掛PageHelper 步驟 第一步:首先整合MyBatis 參照之前SpringBoot整合MyBatis.md 第二步

Spring中整合Mybatis外掛PageHelper

1. 使用Maven方式引入分頁外掛 在pom.xml中新增如下依賴: <dependency> <groupId>com.github.pagehelper</groupId> <artif

Mybatis外掛-PageHelper(5.0)的使用

轉:http://blog.csdn.net/u012728960/article/details/50791343 maven依賴 <!-- pagehelper分頁外掛 --> <dependency> <groupId>com

mybatis 外掛pagehelper整合及使用

/** * 獲取任意查詢方法的count總數 * * @param select * @return */ public static long count(ISelect select) { Page<?> page =

Spring Boot實踐——Mybatis外掛PageHelper的使用

出自:https://blog.csdn.net/csdn_huzeliang/article/details/79350425 在springboot中使用PageHelper外掛有兩種較為相似的方式,接下來我就將這兩種方式進行總結。 方式一:使用原生的PageHelper 1.在

【防坑指南】使用Mybatis外掛PageHelper為什麼PageInfo物件出現null的原因

在mybatis中,先匯入pagehelper.jar所需的jar包,然後在sqlMapConfig,xml中配置外掛 <plugins> <!-- com.github.pagehelper為PageHelper類所在包名 --> <plug

mybatis 外掛PageHelper的簡單使用

分頁方式的分類: 邏輯分頁 物理分頁 MyBatis-PageHelper 的使用: 首先在pom.xml配置檔案中增加相關的外掛。 外掛地址:https://github.com/pagehelper/Mybatis-PageHelper <depende

Mybatis外掛PageHelper的配置和使用方法

前言 在web開發過程中涉及到表格時,例如dataTable,就會產生分頁的需求,通常我們將分頁方式分為兩種:前端分頁和後端分頁。 前端分頁 一次性請求資料表格中的所有記錄(ajax),然後在前端快取並且計算count和分頁邏輯,一般前端元件(例如dataTable)會提

MyBatis外掛PageHelper的使用

準備工作 在pom.ml中引入依賴 <!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter --> <dependency&

Mybatis外掛PageHelper使用

MyBatis分頁外掛 Author:SimpleWu 在mybatis中我們需要實現分頁功能,如果我們連線的是mysql我們就要寫mysql的分頁sql,連線oracle就要寫oracle的sql語句,這是很不友好的,而我們針對各種不同的資料庫的分頁我們有一個外掛PageHelper PageHelpe

mybatis外掛PageHelper的簡單使用

外掛叫做PageHelper如果你也在用Mybatis,建議嘗試該分頁外掛,這個一定是最方便使用的分頁外掛。 該外掛目前支援Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種資料庫分頁。 使用方法: 第一步:匯入mybatis的分頁jar包。(

基於Mybatis外掛PageHelper實現功能

使用PageHelper外掛實現分頁功能 分頁的功能幾乎是所有專案必備的功能,在SSM(spring 、springmvc、mybatis)組織的專案中如何實現分頁呢? 下面介紹一種基於mybatis的分頁外掛PageHelper來幫助我們實現分頁的功能。

MyBatisMyBatis外掛PageHelper的使用

  好多天沒寫部落格了,因為最近在實習,大部分時間在熟悉實習相關的東西,也沒有怎麼學習新的東西,這週末學習了MyBatis的一個分頁外掛PageHelper,雖然沒有那麼的強大(我在最後會說明它的缺

mybatis外掛pageHelper簡單實用

工作的框架spring springmvc mybatis3 首先使用分頁外掛必須先引入maven依賴,在pom.xml中新增如下 <!-- 分頁助手 --> <dependency> <groupId>com.githu

MyBatis 外掛 PageHelper 入門介紹

1.簡介 官網:https://pagehelper.github.io/ PageHelper可以說是目前最流行的MyBatis分頁外掛了,它使用起來非常簡單且提供一整套的解決方案。以下,我們以傳統Spring專案為例,介紹如何進行使用。SpringBoot的

05 mybatis外掛pageHelper的使用

1.匯入座標 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version&g

Mybatis外掛PageHelper

1.說明 如果你也在用Mybatis,建議嘗試該分頁外掛,這個一定是最方便使用的分頁外掛。 該外掛目前支援Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種

Mybatis外掛——PageHelper使用與原理介紹

推薦一款Mybatis分頁外掛 以前也寫過一篇博文介紹Mybatis的外掛,以及如何通過Mybatis的外掛功能實現一個自定義的分頁外掛,但是那個外掛的侵入性是比較大的。前段時間遇到了

Mybatis外掛-PageHelper簡介

dialect:預設情況下會使用 PageHelper 方式進行分頁,如果想要實現自己的分頁邏輯,可以實現 Dialect(com.github.pagehelper.Dialect) 介面,然後配置該屬性為實現類的全限定名稱。 下面幾個引數都是針對預設 dialect 情況下的引數。使用自定義 dia

easyui + mybatis 外掛 PageHelper 完成顯示功能(SpringMVC + mybatis 框架)

1、使用 easyUI datagrid 完成前臺分頁展示 <table id="dg" title="產品管理" style="width:700px;height:550px"> <thead>