如何使用PageHelper进行分页测试?

更新于
2026-10-12 12:54:00
1阅读来源:SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计170个文字,预计阅读时间需要1分钟。

如何使用PageHelper进行分页测试?

javaimport java.util.List;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.github.pagehelper.PageHelper;

如何使用PageHelper进行分页测试?

测试pagehelper1

import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import cn.e3mall.mapper.TbItemMapper; import cn.e3mall.pojo.TbItem; import cn.e3mall.pojo.TbItemExample; public class PageHelperTest { public void testPageHelper() { // 初始化spring容器 ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:spring/applicationContext-dao.xml"); // 从容器中获得Mapper代理对象 TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class); // 执行sql语句之前设置分页信息使用PageHelper的startPage方法。 PageHelper.startPage(1, 10); // 执行查询 TbItemExample example = new TbItemExample(); List list = itemMapper.selectByExample(example); // 取分页信息,PageInfo。1、总记录数2、总页数 。当前页码 PageInfo pageInfo = new PageInfo<>(list); System.out.println(pageInfo.getTotal()); System.out.println(pageInfo.getPages()); System.out.println(list.size()); } }

本文共计170个文字,预计阅读时间需要1分钟。

如何使用PageHelper进行分页测试?

javaimport java.util.List;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.github.pagehelper.PageHelper;

如何使用PageHelper进行分页测试?

测试pagehelper1

import java.util.List; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import cn.e3mall.mapper.TbItemMapper; import cn.e3mall.pojo.TbItem; import cn.e3mall.pojo.TbItemExample; public class PageHelperTest { public void testPageHelper() { // 初始化spring容器 ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "classpath:spring/applicationContext-dao.xml"); // 从容器中获得Mapper代理对象 TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class); // 执行sql语句之前设置分页信息使用PageHelper的startPage方法。 PageHelper.startPage(1, 10); // 执行查询 TbItemExample example = new TbItemExample(); List list = itemMapper.selectByExample(example); // 取分页信息,PageInfo。1、总记录数2、总页数 。当前页码 PageInfo pageInfo = new PageInfo<>(list); System.out.println(pageInfo.getTotal()); System.out.println(pageInfo.getPages()); System.out.println(list.size()); } }