Maven 环境下在Mybatis中PageHelper分页插件的使用

本文介绍了在Maven工程中使用Mybatis的PageHelper分页插件的步骤,包括添加依赖、配置拦截器以及在业务逻辑中实现分页,同时强调了PageInfo对象能提供丰富的分页信息。
摘要由CSDN通过智能技术生成

1.首先需要在maven工程中引入pagehelper的依赖

<!-- pageHelper分页插件 -->
	<dependency>
	    <groupId>com.github.pagehelper</groupId>
	    <artifactId>pagehelper</artifactId>
    	<version>5.1.11</version>
	</dependency>

2.需要在mybatis-config.xml中配置pagehelper-Interceptor 的plugins

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

3.可以在业务逻辑中使用分页插件进行分页

@RequestMapping("/emps")
	public String getStudents(@RequestParam(value="pn",defaultValue = "1") Integer pn,Model model) {
		
		//设置分页为每页5条数据
		PageHelper.startPage(pn, 5);
		List<Student> allStudent = studentService.getAllStudent();
		//将分页信息包装成pageInfo,并用model传递
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值