1.在pom.xml文件中添加依赖
在maven远程仓库找
https://mvnrepository.com/

<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.6</version>
        </dependency>

2.在mybatis.xml文件中使用pagehelper插件
注意插入时,代码的位置

<!--插件-->
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
    </plugins>

测试类使用pagehelper

public static void main(String[] args) {

        SessionUtil su=new SessionUtil();
        SqlSession session= su.getsession();
        StudentDao dao= session.getMapper(StudentDao.class);
        //pageindex,pagesize
        PageHelper.startPage(5,5);//设置查看的页码和显示条数
        Map m=new HashMap();
        m.put("uname","a");
        List list=dao.findall(m);
        PageInfo p=new PageInfo(list);
        System.out.println("总条数:"+p.getTotal());
        System.out.println("总页数:"+p.getPages());
        System.out.println("上一页:"+p.getPrePage());
        System.out.println("下一页:"+p.getNextPage());
        List<Student> stus=p.getList();
        for (Student stu : stus) {
            System.out.println(stu.getUserid()+","+stu.getUser_name()+","+
                    stu.getAddress()+","+stu.getGrade().getGradename());
        }
     }
10-06 13:29