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容器
* 从Spring容器中获取Mapping代理对象
* 执行查询并分页
* tbItem 是实体类***
*/
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
TbItemMapper tbItemMapper = applicationContext.getBean(TbItemMapper.class);
TbItemExample example = new TbItemExample();
PageHelper.startPage(1, 10);
List<TbItem> list = tbItemMapper.selectByExample(example);
for(TbItem tbItem : list) {
System.out.println(tbItem.getTitle());
}
//获取分页信息
PageInfo<TbItem> pageInfo = new PageInfo(list);
Long long1 = pageInfo.getTotal();
System.out.println("一共有数据:"+long1+"条。");
}
}