一、Mybatis-Plues自带分页插件
1.分页插件配置
package com.xxxx.server.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MyBatis分页配置
* @author zhoubin
* @since 1.0.0
*/
@Configuration
public class MyBatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor(){
return new PaginationInterceptor();
}
}
2.开启分页插件
//开启分页
Page<Employee> page = new Page<>(currentPage,Pagesize);
//查询结果返回对象
IPage<Object>
二、项目中使用PageHelper
1.第一步:添加依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>3.4.2</version>
</dependency>
2.在Controller调用Service的时候,调用PageHelper
@RequestMapping("/sysadmin/dept/list")
public String toDeptList(Model model, @RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer Pagessize ) {
PageHelper.startPage(currentPage, Pagesize);
List<Dept> deptList = deptService.findAll();
PageInfo<Dept> p = new PageInfo<>(deptList);
model.addAttribute("deptList", deptList);
model.addAttribute("page", p);
return "sysadmin/dept/jDeptList";
}