zoukankan      html  css  js  c++  java
  • Mybatis学习笔记11:PageHelper分页插件

    1、引入PageHelper的包

    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper</artifactId>
        <version>最新版本</version>
    </dependency>
    

    2、使用


    @Test
    	public void test01() throws IOException {
    		// 1、获取sqlSessionFactory对象
    		SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
    		// 2、获取sqlSession对象
    		SqlSession openSession = sqlSessionFactory.openSession();
    		try {
    			EmployeeMapper mapper = openSession.getMapper(EmployeeMapper.class);
    			Page<Object> page = PageHelper.startPage(5, 1);
    			
    			List<Employee> emps = mapper.getEmps();
    			//传入要连续显示多少页
    			PageInfo<Employee> info = new PageInfo<>(emps, 5);
    			for (Employee employee : emps) {
    				System.out.println(employee);
    			}
    			/*System.out.println("当前页码:"+page.getPageNum());
    			System.out.println("总记录数:"+page.getTotal());
    			System.out.println("每页的记录数:"+page.getPageSize());
    			System.out.println("总页码:"+page.getPages());*/
    			///xxx
    			System.out.println("当前页码:"+info.getPageNum());
    			System.out.println("总记录数:"+info.getTotal());
    			System.out.println("每页的记录数:"+info.getPageSize());
    			System.out.println("总页码:"+info.getPages());
    			System.out.println("是否第一页:"+info.isIsFirstPage());
    			System.out.println("连续显示的页码:");
    			int[] nums = info.getNavigatepageNums();
    			for (int i = 0; i < nums.length; i++) {
    				System.out.println(nums[i]);
    			}
    			
    			
    			//xxxx
    		} finally {
    			openSession.close();
    		}
    
    	}
    
  • 相关阅读:
    【NOIP2018PJ正式赛】摆渡车
    【NOIP2018PJ正式赛】龙虎斗
    【NOIP2018PJ正式赛】标题统计
    高精度除单精度
    关于输出的东东
    高精度乘单精度
    【NOIP2012模拟10.26】电影票
    【NOIP2012模拟10.26】雕塑
    【NOIP2012模拟10.26】火炬手
    【NOIP2016提高A组模拟9.7】千帆渡
  • 原文地址:https://www.cnblogs.com/xidianzxm/p/12459176.html
Copyright © 2011-2022 走看看