pagehelper分页工具的使用

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插件
注意插入时,代码的位置
在MyBatis 的总体文件中配置插件
放到environments default="development标签之前

   <plugins>  
      <!-- PageHelper4.1.6 -->   
      <plugin interceptor="com.github.pagehelper.PageHelper">  
           <property name="dialect" value="oracle"/>        
     </plugin>  
  </plugins>  

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

<!--插件-->
    <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.getPageNum());
        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());
        }
     }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值