欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot整合PageHelper分頁無效的常見原因分析

 更新時間:2024年08月27日 08:45:14   作者:lntanjialiang521  
這篇文章主要介紹了SpringBoot整合PageHelper分頁無效的常見原因分析,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

SpringBoot整合PageHelper分頁無效的常見原因

1.maven依賴的問題

此類原因是與pom.xml文件中引入的分頁依賴有關(guān)

由于springboot本身集成pagerhelper的分頁插件

只需要引入如下依賴即可

<!-- spring-boot mybatis pagehelper -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.10</version>
</dependency>

如引入的為如下依賴

需要添加Bean注入(如何添加請自行百度)

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

2.執(zhí)行PageHelper.startPage(int pageNum, int pageSize)

后沒有緊跟分頁查詢,而是先執(zhí)行了其他查詢

如下初始化分頁器后,應(yīng)該緊跟mybatis的分頁查詢語句,方法中如有其他查詢需求,需要在其他查詢完成后,再執(zhí)行PageHelper.startPage(int pageNum, int pageSize)方法

	public PageInfo<R> page(Map<String, ? extends Object> map) {
		//獲取第1頁,10條內(nèi)容,默認(rèn)查詢總數(shù)count
	    PageHelper.startPage(Integer.parseInt(map.get("pageNum").toString()), Integer.parseInt(map.get("pageSize").toString()));
	    String sql = String.format("%s%s",sqlMapping , map.get("mapping")==null?"getPageObjList" : map.get("mapping")) ;
		List<R> l = sqlSessionTemplate.selectList(sql , map);
		return new PageInfo<R>(l);
	}

3.沒有配置mybatis的分頁攔截器(也是我遇到的問題)

當(dāng)攔截器沒有配置的時候,每次進(jìn)行List查詢都會返回全部結(jié)果數(shù)據(jù),此時需要在啟動類中注入攔截器類

	@Bean
	public Interceptor[] plugins() {
		return new Interceptor[]{new PageInterceptor()};
	}

或者在MyBatis的配置文件mybatis-config.xml中添加如下代碼

<configuration> 
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
	</plugins>
</configuration>

總結(jié)

以上就是綜合網(wǎng)上大家遇到的springboot使用pagehelper進(jìn)行分頁時,遇到查詢出全部數(shù)據(jù)而沒有進(jìn)行分頁的常見問題及解決方案。

這些僅為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論