PageHelper测试分页插件
来源:互联网 发布:孔雀为什么东南飞 知乎 编辑:程序博客网 时间:2024/06/16 09:07
步骤一,在maven的pom.xml文件中添加相应的依赖,mybatis的依赖,相应Jdbc驱动的依赖,PageHelper的依赖
PageHelper的依赖如下
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.2.1</version>
</dependency>
在resource下新建一个spring文件夹
测试代码:
package com.taotao.dao;
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;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.List;
/**
* 测试Mybatis分页插件
*/
public class TestPageHelper {
@Test
public void testPageHelper() throws Exception {
//1,创建一个Spring容器
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
//2,从spring容器中获得Mapper的代理对象
TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class);
//3,设置分页信息
PageHelper.startPage(1, 30);
//4,执行查询
TbItemExample tbItemExample = new TbItemExample();
List<TbItem> tbItemsList = itemMapper.selectByExample(tbItemExample);
//5,取分页结果
PageInfo<TbItem> pageInfo = new PageInfo<>(tbItemsList);
long total = pageInfo.getTotal();
System.out.println("total:" + total);
int pages = pageInfo.getPages();
System.out.println("pages:" + pages);
int pageSize = pageInfo.getPageSize();
System.out.println("pageSize:" + pageSize);
List<TbItem> list = pageInfo.getList();
System.out.println("list:" + list);
}
}
PageHelper的依赖如下
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.2.1</version>
</dependency>
在resource下新建一个spring文件夹
测试代码:
package com.taotao.dao;
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;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.List;
/**
* 测试Mybatis分页插件
*/
public class TestPageHelper {
@Test
public void testPageHelper() throws Exception {
//1,创建一个Spring容器
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
//2,从spring容器中获得Mapper的代理对象
TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class);
//3,设置分页信息
PageHelper.startPage(1, 30);
//4,执行查询
TbItemExample tbItemExample = new TbItemExample();
List<TbItem> tbItemsList = itemMapper.selectByExample(tbItemExample);
//5,取分页结果
PageInfo<TbItem> pageInfo = new PageInfo<>(tbItemsList);
long total = pageInfo.getTotal();
System.out.println("total:" + total);
int pages = pageInfo.getPages();
System.out.println("pages:" + pages);
int pageSize = pageInfo.getPageSize();
System.out.println("pageSize:" + pageSize);
List<TbItem> list = pageInfo.getList();
System.out.println("list:" + list);
}
}
阅读全文
0 0
- PageHelper测试分页插件
- MyBatis分页插件PageHelper
- mybatis分页插件pagehelper
- Mybaties PageHelper分页插件
- Mybatis分页插件-pagehelper
- Mybatis分页插件 - PageHelper
- Mybatis分页插件PageHelper
- PageHelper分页插件使用
- 分页插件PageHelper
- Mybatis分页插件PageHelper
- PageHelper分页插件使用
- 分页插件PageHelper
- MyBatis分页插件PageHelper
- mybatis插件分页PageHelper
- Mybatis分页插件PageHelper
- 分页插件PageHelper使用方法
- 分页插件pageHelper
- 分页插件PageHelper
- Hibbard增量的希尔排序思考——如何证明其减枝条件
- An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application to S
- 计算机的运算方法
- 【SpringMVC学习】SpringMVC介绍
- 【HDU】 1215
- PageHelper测试分页插件
- 关于利用Gson转json
- 如何下载网页中的视频?
- sklearn的认识
- zepto--学习demo1
- OJ1104: 求因子和(函数专题)
- C++中的模板类vector
- 容易看错结果几个小程序
- Unbutu学习记录