实现步骤
- 通过扩展Mapper实现分页查询:
- 为Mapper.xml搜索节点
- 为Mapper.class 添加对应的搜索方法
1 BasePage分类
/**
* 分页工具类
*/
public class BasePage {
protected Integer page;
protected Integer pageSize;
protected Integer skip;
protected Integer totalPage;
protected Integer totalSize;
public Integer getPage() {
return page;
}
public void setPage(Integer page) {
this.page = page;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getSkip() {
return (page-1)*pageSize;
}
public void setSkip(Integer skip) {
this.skip = skip;
}
public Integer getTotalPage() {
return (this.totalSize - 1) / this.pageSize + 1;
}
public Integer getTotalSize() {
return totalSize;
}
public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
}
public void setTotalSize(Integer totalSize) {
this.totalSize = totalSize;
}
}
2 搜索节点示例
<select id="selectPageByExample" resultMap="BaseResultMap" parameterType="com.wanliyun.ss.entity.OrderExample" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Wed Nov 16 11:34:18 CST 2016.
-->
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from order
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
limit ${skip},${pageSize}
</select>
3 Mapper 方法名
List<Order> selectPageByExample(OrderExample example);
4 使用案例片段
example.setPage(basePage.getPage());
example.setPageSize(basePage.getPageSize());
example.setOrderByClause("exam_number asc");
list = this.mapper.selectPageByExample(example);