首先,在mybatis-config.xml中添加如下配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 配置分页插件 -->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!--分页参数合理化 -->
<property name="reasonable" value="true"/>
</plugin>
</plugins>
</configuration>
后台接口应用实例:
public Map<String,Object> definations(
@RequestParam(value="pageNo", defaultValue="1", required=false) Integer pageNo,
@RequestParam(value="pageCount", defaultValue="10", required=false) Integer pageCount,
@RequestParam(value="keyword", required=false) String keyword) {
// 引入PageHelper分页插件
// 在查询之前只需要调用,传入页码,以及每页的大小
PageHelper.startPage(pageNo, pageCount);
// 分页查询得到结果集
// 使用pageInfo包装查询后的结果,只需要将pageInfo交给页面就行了。
// 封装了详细的分页信息,包括有我们查询出来的数据,传入连续显示的页数
PageInfo<ProcessDefinition> page = workFlowDefinationService.findPorcessDefinationByPage(pageNo, pageCount, keyword);
//保存结果集带到页面显示
map.put("page", page);
map.put("pageNo", pageNo);
map.put("pageCount", pageCount);
//保存模糊查询条件以便回显
map.put("keyword", keyword);
return map;
}