分页处理

  

package com.taotao.controller;

import java.util.List;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.mapper.TbItemMapper;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemExample;

public class testPageHelper {
@Test

public void testPageHelper(){

//创建一个spring容器
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");

//从spring容器中获取mapper代理对象

TbItemMapper mapper = applicationContext.getBean(TbItemMapper.class);

//执行查询并分页
TbItemExample example = new TbItemExample();

//分页处理
PageHelper.startPage(1, 10);

List<TbItem> list = mapper.selectByExample(example);
//取商品列表
for (TbItem tbItem : list) {
System.out.println(tbItem.getTitle());
}

PageInfo<TbItem> pageInfo = new PageInfo<>(list);

long total = pageInfo.getTotal();
System.out.println("总有商品"+ total + "条信息");



}
}

原文地址:https://www.cnblogs.com/xiaohouzai/p/6838412.html