mybaits 分页插件 pageHelper5.0.2
2017-08-18 17:38
344 查看
Mybatis的分页插件,那么PageHelper一定会是你的首选。这一定会是使用最方便的分页插件。这个插件它支持任何复杂的单表,多表分页。
如果你使用 Maven,你只需要在 pom.xml 中添加下面的依赖:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- 加载mybatis的全局配置文件 -->
<property name="mapperLocations">
<array>
<value>classpath:mapping/*.xml</value>
</array>
</property>
<!-- <property name="configLocation" value="classpath:sqlMapConfig.xml" /> -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>
helperDialect=mysql
</value>
</property>
</bean>
</array>
</property>
</bean>
配置结束后,进入正题,创建一个查询语句,用了pageHelper 查询语句与之前的一样。
select
<include refid="product"></include>
from product
where 1 = 1查询一个product 的表:
/**
* 产品管理界面
*
* @param request
* @param model
* @return
*/
@RequestMapping(value = "productManage")
private String productManage(HttpServletRequest request, Model model, ProductDetail productDetail,
@RequestParam(required = true, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
PageHelper.startPage(page, pageSize);
List<ProductDetail> productDetails = productService.getProductManage(productDetail);
PageInfo<ProductDetail> p = new PageInfo<ProductDetail>(productDetails);
/**
* 返回产品查询信息
*/
model.addAttribute("productDetail", productDetail);
/**
* 返回产品信息集合
*/
model.addAttribute("productDetails", productDetails);
/**
* 分页配置信息返回
*/
model.addAttribute("page", p);
return "manage/product/productManage";
}
PageHelper.startPage(page, pageSize);
这段代码表示,程序开始分页了,page默认值是1,pageSize默认是10,意思是从第1页开始,每页显示10条记录。
如果你使用 Maven,你只需要在 pom.xml 中添加下面的依赖:
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.0.2</version> </dependency>接着,在spring-mybatis.xml中是这样配置:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- 加载mybatis的全局配置文件 -->
<property name="mapperLocations">
<array>
<value>classpath:mapping/*.xml</value>
</array>
</property>
<!-- <property name="configLocation" value="classpath:sqlMapConfig.xml" /> -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<value>
helperDialect=mysql
</value>
</property>
</bean>
</array>
</property>
</bean>
配置结束后,进入正题,创建一个查询语句,用了pageHelper 查询语句与之前的一样。
select
<include refid="product"></include>
from product
where 1 = 1查询一个product 的表:
/**
* 产品管理界面
*
* @param request
* @param model
* @return
*/
@RequestMapping(value = "productManage")
private String productManage(HttpServletRequest request, Model model, ProductDetail productDetail,
@RequestParam(required = true, defaultValue = "1") Integer page,
@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
PageHelper.startPage(page, pageSize);
List<ProductDetail> productDetails = productService.getProductManage(productDetail);
PageInfo<ProductDetail> p = new PageInfo<ProductDetail>(productDetails);
/**
* 返回产品查询信息
*/
model.addAttribute("productDetail", productDetail);
/**
* 返回产品信息集合
*/
model.addAttribute("productDetails", productDetails);
/**
* 分页配置信息返回
*/
model.addAttribute("page", p);
return "manage/product/productManage";
}
PageHelper.startPage(page, pageSize);
这段代码表示,程序开始分页了,page默认值是1,pageSize默认是10,意思是从第1页开始,每页显示10条记录。
相关文章推荐
- Mybaits 基于pagehelper分页插件
- Mybatis pagehelper分页插件使用
- Mybatis分页插件 - PageHelper
- MyBatis中如何使用PageHelper插件实现 分页
- mybatis的分页插件 PageHelper、超级简单实用
- SpringBoot之分页插件PageHelper的使用
- 使用mybatis时选择分页插件PageHelper 5.0.0
- Mybatis分页插件PageHelper正确的使用方法(网上有2篇不够科学的文章)
- Mybatis分页插件PageHelper的配置和简单使用方法(推荐)
- MyBatis拦截器分页原理及PageHelper分页插件教学
- SpringBoot集成MyBatis的分页插件PageHelper(回头草)
- mybatis 分页插件PageHelper3.7.4试用
- Mybatis 的分页插件 PageHelper的使用注意事项
- MyBatis学习总结(17)——Mybatis分页插件PageHelper
- Mybatis分页插件PageHelper的使用
- spring-boot | 整合通用Mabatis 分页插件PageHelper
- mybatis分页插件 pagehelper配置pagehelper
- 分页插件pageHelper工作中的简单使用
- Spring + Mybatis 使用 PageHelper 插件分页
- Mybatis分页插件 - PageHelper与springBoot的整合