分頁處理
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 + "條信息");
}
}
分頁處理