使用Mybatis的PageHelper分页工具的教程详解

网友投稿 1208 2023-04-20

使用Mybatis的PageHelper分页工具的教程详解

使用Mybatis的PageHelper分页工具的教程详解

1、导入相关的jar包

在pom.xm中加入

com.github.pagehelper

pagehelper

5.1.10

2、在Mybatis的配置文件mybatis-config.xml中加入以下代码

在controller中编写代码引用

@RequestMapping(value = "/emps")

public String GetEmployees(@RequestParam(value = "pn",

defaultValue ="1")Integer pn , Model model){

PageHelper.startPage(pn,8);

List employeeslist = employeeService.GetEmployees();

PageInfo page = new PageInfo(employeeslist,7);

model.addAttribute("pageinfo",page);

return "list";

}

PS:下面看下PageHelper的简单使用(强大的分页工具)

1.使用maven解决依赖

com.github.pagehelper

pagehelper

3.4.2

2.在Controller调用Service的时候,调用PageHelper

@RequestMapping("/sysadmin/dept/list")

public String toDeptList(Model model,@RequestParam(required = false,defaultValue = "1",value = "pn")Integer pn ) {

PageHelper.startPage(pn, 8);

List deptList = deptService.fWVHSciindAll();

PageInfo p = new PageInfo<>(deptList);

model.addAttribute("deptList", deptList);

model.addAttribute("page", p);

return "sysadmin/dept/jDeptList";

}

PageHelper.startPage(pn, 8);     //参数分别是设置当前的页数和每页的数量

PageInfo  p = new PageInfo<>(deptList);  //将得到查询结果集进行封装

3.在jsp页面进行简单的分页

首页

上一页

上一页

下一页

下一页

最后页

一共${page.pages}页 --当前页是${page.pageNum } -- 共有${page.total }条数据

简单的进行了调用,实现了基本的功能(使用pageInfo的相关属性)

总结

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:电脑打开小程序不显示画面(电脑的小程序显示到上面去了咋弄)
下一篇:springboot2.0 配置时间格式化不生效问题的解决
相关文章

 发表评论

暂时没有评论,来抢沙发吧~