pagehelper分页工具的使用

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


        
            com.github.pagehelper
            pagehelper
            5.1.6
        

2.在mybatis.xml文件中使用pagehelper插件
注意插入时,代码的位置
在MyBatis 的总体文件中配置插件
放到environments default="development标签之前

     
         
        
                   
       
    

插件5.1以后interceptor不同,并且不需要指定数据库名字


    
        
    

测试类使用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.getPageNum());
        System.out.println("上一页:"+p.getPrePage());
        System.out.println("下一页:"+p.getNextPage());
        List stus=p.getList();
        for (Student stu : stus) {
            System.out.println(stu.getUserid()+","+stu.getUser_name()+","+
                    stu.getAddress()+","+stu.getGrade().getGradename());
        }
     }

你可能感兴趣的:(三阶段.mybatis)