spring boot集成pagehelper(兩種方式)
參看了pagehelper-spring-boot,使用起來非常放方便,關(guān)于更多PageHelper可以點擊https://github.com/pagehelper/Mybatis-PageHelper。
當spring boot集成好mybatis時候需要進行分頁,我們首先添加maven支持
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.2</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-autoconfigure</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>
方式一:我們在application.yml(spring 需要讀取的yml)中加入
pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql
然后重啟即可。
配置文件最終會被java所讀取,最終注入到spring bean中,所以我們方法二是配置其bean類,熱加載方便修改當然方式一更簡單,
方式二:在注解涵蓋package下面新建PageHeleperConfig
import com.github.pagehelper.PageHelper; import java.util.Properties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @author zhuxiaomeng * @date 2018/1/2. * @email 154040976@qq.com */ @Configuration public class PageHelperConfig { @Bean public PageHelper getPageHelper(){ PageHelper pageHelper=new PageHelper(); Properties properties=new Properties(); properties.setProperty("helperDialect","mysql"); properties.setProperty("reasonable","true"); properties.setProperty("supportMethodsArguments","true"); properties.setProperty("params","count=countSql"); pageHelper.setProperties(properties); return pageHelper; } }
pageHelper 基礎(chǔ)知識為:
import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper;
Page<T> tPage= PageHelper.startPage(page,limit);
下一句的查詢語句來進行分頁。你只需要用List<T>接收
如果你有疑問可以下載開源項目lenos 快速開發(fā)腳手架,spring boot 版本來熟悉學習。
地址:https://gitee.com/bweird/lenosp
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue+springboot前后端分離工程跨域問題解決方案解析
這篇文章主要介紹了vue+springboot前后端分離工程跨域問題解決方案解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-03-03Gradle構(gòu)建基本的Web項目結(jié)構(gòu)
這篇文章主要為大家介紹了Gradle創(chuàng)建Web項目基本的框架結(jié)構(gòu)搭建,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-03-03完美解決在Servlet中出現(xiàn)一個輸出中文亂碼的問題
下面小編就為大家?guī)硪黄昝澜鉀Q在Servlet中出現(xiàn)一個輸出中文亂碼的問題。小編覺得挺不錯的現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01java并發(fā)包工具CountDownLatch源碼分析
這篇文章主要為大家介紹了java并發(fā)包工具CountDownLatch源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10