1、引入依赖pom.xml
<dependencies> <!--分页插件--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.4.2</version> </dependency> </dependencies>
2、ServiceImpl
@Service public class EmpServiceImpl implements EmpService { @Autowired private EmpMapper empMapper; @Override public PageBean pageList(String name, Integer gender, LocalDate begin, LocalDate end, Integer page, Integer pageSize) { // 开启分页查询 PageHelper.startPage(page,pageSize); // 查询 List<Emp> empList = empMapper.pageList(name,gender,begin,end); // 放入查询结果 Page<Emp> p = (Page<Emp>) empList; // 填充返回结果 PageBean pageBean = new PageBean(p.getTotal(),p.getResult()); return pageBean; } }