Spring Boot系列教程十一: Mybatis使用分页插件PageHelper
来源:互联网 发布:网络浪涌保护器 编辑:程序博客网 时间:2024/06/06 12:56
一.前言
上篇博客中介绍了spring boot集成mybatis的方法,基于上篇文章这里主要介绍如何使用分页插件PageHelper。在MyBatis中提供了拦截器接口,我们可以使用PageHelp最为一个插件装入到SqlSessionFactory,实现拦截器功能。
二.实现
pom.xml文件中添加依赖包
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.1.0</version></dependency>
创建MybatisConf类
package com.woniu.mybatisconf;import java.util.Properties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import com.github.pagehelper.PageHelper;/* * 注册MyBatis分页插件PageHelper */@Configurationpublic class MybatisConf { @Bean public PageHelper pageHelper() { System.out.println("MyBatisConfiguration.pageHelper()"); PageHelper pageHelper = new PageHelper(); Properties p = new Properties(); p.setProperty("offsetAsPageNum", "true"); p.setProperty("rowBoundsWithCount", "true"); p.setProperty("reasonable", "true"); pageHelper.setProperties(p); return pageHelper; }}
这时就可以使用PageHelp插件了,在controller中直接使用。
package com.woniu.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import com.github.pagehelper.PageHelper;import com.woniu.bean.User;import com.woniu.mapper.UserMaper;@RestController@RequestMapping("/web")public class WebController { @Autowired private UserMaper mapper; @RequestMapping("/index") public List<User> selectAge(int age){ /* * 第一个参数是第几页;第二个参数是每页显示条数。 */ PageHelper.startPage(1,2); return mapper.Select(age); }}
该工程"springboot_mybatis_demo2"下载地址: 点击打开链接
更多技术文章请关注微信公众号“Java架构师之路”:
1 0
- Spring Boot系列教程十一: Mybatis使用分页插件PageHelper
- Spring Boot系列教程八: Mybatis使用分页插件PageHelper
- Spring Boot系列六 Spring boot集成mybatis、分页插件pagehelper
- Spring + Mybatis 使用 PageHelper 插件分页
- Maven+Spring + Mybatis 使用 PageHelper 插件分页
- Spring + Mybatis 使用 PageHelper 插件分页
- Spring + Mybatis 使用 PageHelper 插件分页
- Spring + Mybatis 使用 PageHelper 插件分页
- Spring Boot+Mybatis+Pagehelper分页
- Spring Boot+Mybatis+Pagehelper分页
- 关于Spring+mybatis+PageHelper分页插件PageHelper的使用策略
- Spring+mybatis+PageHelper分页插件PageHelper的使用
- Mybatis 使用 PageHelper 插件分页
- mybatis pagehelper分页插件使用
- Mybatis 使用 PageHelper 插件分页
- Mybatis pagehelper分页插件使用
- spring+mybatis利用pageHelper分页插件分页
- Spring Boot : 集成mybatis、pagehelper插件、开启事务、druid数据源配置、mybatis-generator(十一)
- 微信小程序css篇----flex模型
- 88. Merge Sorted Array*
- 设计模式----组合模式
- 问题三十六:ray tracing中的Inverse Mapping(1)——球面Inverse Mapping
- 类:基础电子书
- Spring Boot系列教程十一: Mybatis使用分页插件PageHelper
- Android之---沉浸式状态栏的错误理解(官方有沉浸模式的感念但是没有沉浸式状态栏的说法)
- tomcat 7
- JVM内存管理之内存回收策略
- 迭代深搜+A*(IDA*)
- @import调用css和link href调用区别
- ORA-01102: cannot mount database in EXCLUSIVE mode
- 欢迎使用CSDN-markdown编辑器
- 上下界网络流学习总结