PageHelper-分页插件
分页插件 PageHelper 使用
https://github.com/pagehelper/Mybatis-PageHelper
SSM
https://github.com/abel533/Mybatis-Spring
pom.xml
引入 依赖1
2
3
4
5
6<!-- 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>spring 配置拦截器
com.github.pagehelper.PageInterceptor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:mapping/*.xml" />
<property name="databaseIdProvider" ref="databaseIdProvider" />
<!-- 插件配置 -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<!-- 什么都不配,使用默认的配置 -->
<value></value>
</property>
</bean>
</array>
</property>
</bean>使用
Controller
文件1
2
3
4
5
6
7
8
9//分页条件
Integer page = StringEx.tInteger(request.getParameter("page"));
Integer rows = StringEx.tInteger(request.getParameter("rows"));
PageInfo<WxuserDto> pageInfo = this.wxuserService.selectWxuserByPage(wxuserDto, page, rows);
Map<String, Object> map = new HashMap<>();
map.put("total", pageInfo.getTotal());
map.put("rows", pageInfo.getList());
this.writeJson(map, request, response);ServiceImpl
文件1
2
3
4
5//放到 DAO 接口执行代码上面一行位置
PageHelper.startPage(page,rows);
List<Wxuser> list = wxuserDao.selectWxuserByPage(map);
PageInfo<Wxuser> pageInfo = new PageInfo<>(list);
Spring Boot
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 王文哲的博客!