Mybatis分页插件
mybatis配置
<!-- mybatis分页插件 -->
<bean id="pagehelper" class="com.github.pagehelper.PageHelper">
<property name="properties">
<props>
<prop key="offsetAsPageNum">true</prop>
<prop key="rowBoundsWithCount">true</prop>
<prop key="pageSizeZero">true</prop>
<prop key="reasonable">false</prop>
<prop key="supportMethodsArguments">false</prop>
</props>
</property>
</bean> <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/*/mapping/*.xml"></property>
<property name="plugins">
<list>
<!-- <ref bean="offsetLimitIntercepter" /> -->
<ref bean="pagehelper" />
</list>
</property>
</bean>
java 类,写一个class继承这个抽象类
public abstract class AbstractPageForm<T extends AbstractPageForm<T>> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* @Description 页码为首页
*/
@DefaultValue("1")
@QueryParam("pageNum")
protected int pageNum = 1;
/**
* @Description 每页显示数量,默认为10
*/
@DefaultValue("10")
@QueryParam("pageSize")
protected int pageSize = 10;
public int getPageNum() {
return pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
/**
* @Title enablePaging
* @Description 启用分页
* @return
*/
@SuppressWarnings("unchecked")
public final T enablePaging() {
PageHelper.startPage(pageNum, pageSize);
return (T) this;
}
}
mapper.xml (CourseForm继承了AbstractPageForm的抽象类)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.*.*DAO" >
<resultMap id="BaseResultMap" type="com.*.Class" >
<id column="id" property="id" jdbcType="INTEGER" /> </resultMap> <select id="selectCourseList" resultMap="BaseResultMap" parameterType="com.*.form.CourseForm" >
select
<include refid="Base_Column_List" />
from TABLE_NAME
</select> </mapper>
分页类示例:
@Override
public PageInfo<Class> queryList(CourseForm courseForm) {
//Class需要替换成自己的类
List<Class> selectList = organizationDAO.selectList(courseForm.enablePaging());
PageInfo<Class> pageInfo = new PageInfo<Class>(selectList);
return pageInfo;
}
pageInfo,POM配置
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.5</version>
</dependency>
Mybatis分页插件的更多相关文章
- mybatis分页插件以及懒加载
1. 延迟加载 延迟加载的意义在于,虽然是关联查询,但不是及时将关联的数据查询出来,而且在需要的时候进行查询. 开启延迟加载: <setting name="lazyLoading ...
- Mybatis分页插件PageHelper的配置和使用方法
Mybatis分页插件PageHelper的配置和使用方法 前言 在web开发过程中涉及到表格时,例如dataTable,就会产生分页的需求,通常我们将分页方式分为两种:前端分页和后端分页. 前端分 ...
- Mybatis分页插件PageHelper使用
一. Mybatis分页插件PageHelper使用 1.不使用插件如何分页: 使用mybatis实现: 1)接口: List<Student> selectStudent(Map< ...
- SSM 使用 mybatis 分页插件 pagehepler 实现分页
使用分页插件的原因,简化了sql代码的写法,实现较好的物理分页,比写一段完整的分页sql代码,也能减少了误差性. Mybatis分页插件 demo 项目地址:https://gitee.com/fre ...
- Mybatis分页插件——PageHelper
1.引入依赖 <!-- mybatis分页插件 --> <dependency> <groupId>com.github.pagehelper</groupI ...
- Java SSM框架之MyBatis3(三)Mybatis分页插件PageHelper
引言 对于使用Mybatis时,最头痛的就是写分页,需要先写一个查询count的select语句,然后再写一个真正分页查询的语句,当查询条件多了之后,会发现真不想花双倍的时间写count和select ...
- Mybatis学习---Mybatis分页插件 - PageHelper
1. Mybatis分页插件 - PageHelper说明 如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件. 该插件目前支持Oracle,Mysql,MariaDB,S ...
- Mybatis分页插件PageHelper的实现
Mybatis分页插件PageHelper的实现 前言 分页这个概念在做web网站的时候很多都会碰到 说它简单吧 其实也简单 小型的网站,完全可以自己写一个,首先查出数据库总条数,然后按照分页大小分为 ...
- 基于Mybatis分页插件PageHelper
基于Mybatis分页插件PageHelper 1.分页插件使用 1.POM依赖 PageHelper的依赖如下.需要新的版本可以去maven上自行选择 <!-- PageHelper 插件分页 ...
随机推荐
- mybatis 中sql语句传递多个参数
Available parameters are [2, 1, 0, param1, param2, param3] <select id="loginByTeacher" ...
- Visual studio智能感知挡住了当前代码输入行
AssistX->Listboxes->Enable Visual Assist completion, suggestion and member list in .. 如果勾选了该项就 ...
- <<Exceptional C++>> notes
- class Complex { public: ) : real_(real), imaginary_(imaginary) { } Complex& operaor+=(const Co ...
- MVC4 +EasyUI 使用TreeGrid 方法
用easyui已经有2年了,换了新环境,要求用mvc开发,所以想把原来的项目直接用mvc重构. 在使用TreeGird的时候出现了问题,发现在转换为treegrid的json 很费劲,一直都是用的ea ...
- OAF_开发系列15_实现OAF组件重用和继承(案例)
20150717 Created By BaoXinjian
- 使用Visual Studio调试用户模式进程(Debugging a User-Mode Process Using Visual Studio)
由于本人能力有限,翻译不足之处敬请谅解,欢迎批评指正:sunylat@163.com Visual Studio版本:Visual Studio 2015企业版,中文环境. MSDN原文:https: ...
- 从高处理解android与服务器交互(看懂了做开发就会非常的容易)
今天帮一个朋友改一个bug 他可以算是初学者吧 .我给他看了看代码,从代码和跟他聊天能明显的发现他对客户端与服务器交互 基本 不是很了解.所以我花了更多时间去给他讲客户端与服务器的关系.我觉得从这个高 ...
- SQL语句Where中使用别名作为判断条件
当我们使用某个表达式作为输出的一列时,我们无法再Where条件中直接使用该列作判断条件. 例如下面的SQL语句: select id, (c1 + c2) as s from t1 where ...
- Partitioning & Archiving tables in SQL Server (Part 1: The basics)
Reference: http://blogs.msdn.com/b/felixmar/archive/2011/02/14/partitioning-amp-archiving-tables-in- ...
- WinForm DataGridView分页功能
WinForm 里面的DataGridView不像WebForm里面的GridView那样有自带的分页功能,需要自己写代码来实现分页,效果如下图: 分页控件 .CS: 1 using System; ...