使用插件分页

1.配置(可以在mybatis配置文件中配拦截器,也可以在spring配置文件中配)

1、在ssm项目的spring.xml中配置:
<!-- sqlsessionFactory -->
	<bean class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation" value="classpath:mybatis-config.xml"></property>
		<property name="dataSource" ref="dataSource"></property>
		<property name="plugins">
			<array>
				<bean class="com.github.pagehelper.PageInterceptor"></bean>
			</array>
		</property>
	</bean>

2、或者在mybatis-config.xml中配置(一般ssm项目配第一个spring.xml就可以了,这个是在有mybatis配置文件的项目里面配):

<!--注意这里要写成PageInterceptor, 5.0之前的版本都是写PageHelper, 5.0之后要换成PageInterceptor -->
<plugins>
	<plugin interceptor="com.github.pagehelper.PageInterceptor">
		<!--reasonable:分页合理化参数,默认值为false,直接根据参数进行查询。 当该参数设置为 true 时,pageNum<=0 
			时会查询第一页, pageNum>pages(超过总数时),会查询最后一页。 -->
	<property name="reasonable" value="true"/>
	</plugin>
</plugins>

3.使用
后端:

前端:

posted on   鹏星  阅读(25)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示