https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md
1
<!--引入pageHelper分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.0.0</version>
</dependency>
2
package com.controller;
import com.bean.Employee;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Controller
public class EmpController {
@Autowired
EmpService empService;
@RequestMapping("/emps")
public String emp(
@RequestParam(value = "pn", defaultValue = "1") Integer pn,
Map<Object,Object> map) {
//pn第一页传入的当前页,每页显示5数据
PageHelper.startPage(pn, 5);
//查询数据
List<Employee> emps = empService.getAll();
//封装,当前页有连续的5条
PageInfo page = new PageInfo(emps,5);
map.put("pageInfo",page);
return "list";
}
}
来源:CSDN
作者:天梯无忌
链接:https://blog.csdn.net/weixin_44663632/article/details/103653617