此文章沒有用到ajax技術實現的分頁功能,純利用spring標籤的前端個人覺得很不好,會導致一些問題。如果你想知道怎麼利用JQuery的ajax方法結合PageHelper進行數據分頁,你可以訪問我另一篇博文:https://blog.csdn.net/VEclipses/article/details/104883278
1.在pox.xml文件注入PageHelper依賴關係
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
2.在dao層中的配置攔截器
<!--配置SessionFactory-->
<!--reasonable=true:分頁參數合理化,即不可能到達-1頁之類不合理的頁數-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeAliasesPackage" value="com.myhomes.entity"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>
helperDialect=mysql
reasonable=true
supportMethodsArguments=true
params=count=countSql
autoRuntimeDialect=true
</value>
</property>
</bean>
</array>
</property>
</bean>
3.dao層配置實體類(這裏不展示)及接口方法,編寫dao類的映射文件
dao接口方法:
映射文件:
4.服務層添加接口及實現類
接口:
實現類:
5.web層的對應控制器類添加路由及進行業務操作
編寫路由接口:/user/listAll
6.準備前端頁面
在modelAndView參數中獲取查詢的列表數據並使用foreach語句循環顯示數據;
顯示分頁相關的數據:
7.結果
下一頁:
如此便完成了。