首页 > 其他 > 详细

分页处理

时间:2017-05-10 22:19:37      阅读:403      评论:0      收藏:0      [点我收藏+]

  

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 + "条信息");



}
}

分页处理

原文:http://www.cnblogs.com/xiaohouzai/p/6838412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!