spring-boot 整合mybatis的分頁外掛PageHelper和Generator
原文地址:http://blog.csdn.net/zl18310999566/article/details/54097273
分頁外掛PageHelper
新增maven依賴
根據上面地址中的說明,只需要新增如下依賴,並且可以不再mybatis的依賴
[html] view plain copy print?- <!--分頁外掛-->
- <dependency>
- <groupId>com.github.pagehelper</groupId>
-
<artifactId
- <version>1.0.0</version>
- </dependency>
攔截器PageInterceptor
PageInterceptor是PageHelper-5.0版本中新的攔截器,com.github.pagehelper.PageHelper則成為了介面Dialect的一個實現類
在攔截器PageInterceptor中可以看到如下內容
[java] view plain copy- private Dialect dialect;
- private String default_dialect_class = "com.github.pagehelper.PageHelper";
- publicvoid setProperties(Properties properties) {
- this.msCountMap = CacheFactory.createCache(properties.getProperty("msCountCache"), "ms", properties);
-
String dialectClass = properties.getProperty("dialect"
- if(StringUtil.isEmpty(dialectClass)) {
- dialectClass = this.default_dialect_class;
- }
- try {
- Class e = Class.forName(dialectClass);
- this.dialect = (Dialect)e.newInstance();
- } catch (Exception var5) {
- thrownew PageException(var5);
- }
- this.dialect.setProperties(properties);
- try {
- this.additionalParametersField = BoundSql.class.getDeclaredField("additionalParameters");
- this.additionalParametersField.setAccessible(true);
- } catch (NoSuchFieldException var4) {
- thrownew PageException(var4);
- }
- }
- pagehelper.dialect=com.github.pagehelper.dialect.helper.MySqlDialect
而在com.github.pagehelper.PageHelper中有以下兩個引數。
- private PageParams pageParams;
- private PageAutoDialect autoDialect;
- publicvoid setProperties(Properties properties) {
- this.pageParams = new PageParams();
- this.autoDialect = new PageAutoDialect();
- this.pageParams.setProperties(properties);
- this.autoDialect.setProperties(properties);
- }
- protectedboolean offsetAsPageNum = false;
- protectedboolean rowBoundsWithCount = false;
- protectedboolean pageSizeZero = false;
- protectedboolean reasonable = false;
- protectedboolean supportMethodsArguments = false;
- privateboolean autoDialect = true;
- privateboolean closeConn = true;
- pagehelper.autoDialect=true
- pagehelper.closeConn=false
- pagehelper.reasonable=true
Pagehelper的使用
我增加了如下測試程式碼。
[plain] view plain copy print?- @RequestMapping("/find/mybatis/page")
- public String findUserPageFromMybatis(HttpServletRequest request, Integer pageNum, Integer pageSize) {
- pageNum = pageNum == null ? 1 : pageNum;
- pageSize = pageSize == null ? 10 : pageSize;
- PageHelper.startPage(pageNum, pageSize);
- List<UserMo> list = userMapper.selectUserList();
- PageInfo pageInfo = new PageInfo(list);
- Page page = (Page) list;
- return "PageInfo: " + JSON.toJSONString(pageInfo) + ", Page: " + JSON.toJSONString(page);
- }
- PageInfo: {
- "endRow": 1,
- "firstPage": 1,
- "hasNextPage": true,
- "hasPreviousPage": false,
- "isFirstPage": true,
-
相關推薦
Spring Boot實踐——Mybatis分頁外掛PageHelper的使用
出自:https://blog.csdn.net/csdn_huzeliang/article/details/79350425 在springboot中使用PageHelper外掛有兩種較為相似的方式,接下來我就將這兩種方式進行總結。 方式一:使用原生的PageHelper 1.在
Spring中整合Mybatis分頁外掛PageHelper
1. 使用Maven方式引入分頁外掛 在pom.xml中新增如下依賴: <dependency> <groupId>com.github.pagehelper</groupId> <artif
spring-boot 整合mybatis的分頁外掛PageHelper和Generator (番外)
分頁外掛PageHelper 新增maven依賴 根據上面地址中的說明,只需要新增如下依賴,並且可以不再mybatis的依賴 <!--分頁外掛--> <dependency> <groupId>com.github.pag
spring-boot 整合mybatis的分頁外掛PageHelper和Generator
原文地址:http://blog.csdn.net/zl18310999566/article/details/54097273 分頁外掛PageHelper 新增maven依賴 根據上面地址中的說明,只需要新增如下依賴,並且可以不再myba
SpringBoot整合MyBatis分頁外掛PageHelper
原創作品,可以轉載,但是請標註出處地址:https://www.cnblogs.com/V1haoge/p/9971043.html SpringBoot整合MyBatis分頁外掛PageHelper 步驟 第一步:首先整合MyBatis 參照之前SpringBoot整合MyBatis.md 第二步
Spring Boot實踐——Mybatis分頁插件PageHelper的使用
page lis 屬性 gen eas col version myba bye 出自:https://blog.csdn.net/csdn_huzeliang/article/details/79350425 在springboot中使用PageHelper插件有兩種
SpringBoot整合Mybatis及分頁外掛pageHelper和事務
spring事務分類: 1.宣告事務 2.程式設計事務 spring事務原理:AOP技術 環繞通知進行攔截 使用spring事務的注意事項:不要Try。因為要將異常丟擲給外層 Springboot預設整合事務,只要在方法上加上@Transactional註解 pom.xml
mybatis 分頁外掛pagehelper整合及使用
/** * 獲取任意查詢方法的count總數 * * @param select * @return */ public static long count(ISelect select) { Page<?> page =
【防坑指南】使用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
SSM整合兩種配置方式——xml和javaConfig,新增分頁外掛pageHelper和通用Mapper
Spring MVC配置 1. xml方式 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
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包。(
Spring Boot 整合Mybatis 之 Mapper外掛(自動生成XML及Mapper程式碼)
pom檔案 主要程式碼 <dependencies> <dependency> <groupId>mysql</groupId> <artifactI
基於Mybatis分頁外掛PageHelper實現分頁功能
使用PageHelper外掛實現分頁功能 分頁的功能幾乎是所有專案必備的功能,在SSM(spring 、springmvc、mybatis)組織的專案中如何實現分頁呢? 下面介紹一種基於mybatis的分頁外掛PageHelper來幫助我們實現分頁的功能。
【MyBatis】MyBatis分頁外掛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的