亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SpringBoot整合PageHelper分頁(yè)無(wú)效的常見原因分析

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

SpringBoot整合PageHelper分頁(yè)無(wú)效的常見原因

1.maven依賴的問(wèn)題

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

由于springboot本身集成pagerhelper的分頁(yè)插件

只需要引入如下依賴即可

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

如引入的為如下依賴

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

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

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

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

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

	public PageInfo<R> page(Map<String, ? extends Object> map) {
		//獲取第1頁(yè),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的分頁(yè)攔截器(也是我遇到的問(wèn)題)

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

	@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)行分頁(yè)時(shí),遇到查詢出全部數(shù)據(jù)而沒有進(jìn)行分頁(yè)的常見問(wèn)題及解決方案。

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

相關(guān)文章

最新評(píng)論