• 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();
    		}
    
    	}
    
  • 相关阅读:
    iOS学习笔记---oc语言第一天
    iOS学习笔记---c语言第十一天
    iOS学习笔记---c语言第十天
    iOS学习笔记---c语言第九天
    iOS学习笔记---c语言第八天
    iOS学习笔记---c语言学习第七天
    iOS学习笔记---c语言第六天
    C语言常用排序全解(转)
    iOS学习笔记---C语言第五天
    iOS学习笔记---C语言第四天
  • 原文地址:https://www.cnblogs.com/xidianzxm/p/12459176.html
Copyright © 2020-2023  润新知