Mybatis PageHelper 简单使用
流程
1,maven 依赖
2,在 mybatis 配置文件启用插件
3,修改 service 层
依赖
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
启用插件
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<property name="helperDialect" value="mysql" />
</plugin>
</plugins>
service 层代码示例
@Service("accountService")
public class AccountServiceImpl implements IAccountService {
@Autowired
private AccountMapper am; @Override
public PageInfo<Account> selectBySearch(Account record, String startDate, String endDate, String companyName,
Integer currentPage, Integer pageSize) { // 如果没有传递分页属性值,默认第一页,每页10条数据
if(currentPage == null) {
currentPage = 1;
}
if(pageSize == null) {
pageSize = 10;
} // 这是关键,设置分页属性
PageHelper.startPage(currentPage, pageSize); // 和 mapper 接口文件中的方法一致
List<Account> list = am.selectBySearch(record, startDate, endDate, companyName); // 分页成功,返回
PageInfo<Account> pageInfo = new PageInfo<>(list);
return pageInfo;
}
}
Mybatis PageHelper 简单使用的更多相关文章
- SpringBoot+Mybatis+PageHelper实现分页
SpringBoot+Mybatis+PageHelper实现分页 mybatis自己没有分页功能,我们可以通过PageHelper工具来实现分页,非常简单方便 第一步:添加依赖 <depend ...
- SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例
SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例 这是一个简单的SpringBoot整合实例 这里是项目的结构目录 首先是pom.xml ...
- MyBatis+PageHelper实现分页
转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7256105.html 前面讲到Spring+SpringMVC+MyBatis深入学习及搭建(十七)--Sp ...
- springboot+mybatis+pagehelper
springboot+mybatis+pagehelper整合 springboot 版本2.1.2.RELEASE mybatis 版本3.5 pagehelper 版本5.18 支持在map ...
- spring + Mybatis + pageHelper + druid 整合源码分享
springMvc + spring + Mybatis + pageHelper + druid 整合 spring 和druid整合,spring 整合druid spring 和Mybatis ...
- Python分页转Mybatis pagehelper格式分页
最近工作里遇到一个需求要把之前用Java写的一个http接口替换成用Python写的,出参是带了mybatis pageHelper中PageInfo信息的一个JSON串,而Python这边分页不会涉 ...
- Mybatis框架简单使用
Mybatis框架简单使用 环境搭建 新建一个JavaWeb项目,在web\WEB-INF\创建lib文件,并且在其下添加Mybatis的核心包以及依赖包,以及Mysql驱动包,junit4测试包等. ...
- MyBatis(1)-简单入门
简介 什么是 MyBatis ? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.My ...
- MyBatis 使用简单的 XML或注解用于配置和原始映射
MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis .My ...
随机推荐
- 使用js做LeetCode
概述 无意中得知了LeetCode这个刷题网站, 深得我意. 其实作为一个程序员, 我是很看重写基础代码的, 因为这个写熟了, 以后学各种语言就不会太困难. 所以我觉得有必要把这件事记下来, 供以后开 ...
- firewall 和 iptables 常用命令
[参考文章]:Centos7 关闭防火墙 [参考文章]:Centos7 firewall防火墙常用配置 CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下 ...
- 解决tomcat启动慢问题
启动慢修改如下: 在catalina.sh中加入这么一行: JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom" 打开$JAVA_ ...
- [EXP]Jenkins 2.150.2 - Remote Command Execution (Metasploit)
## # This module requires Metasploit: https://metasploit.com/download # Current source: https://gith ...
- 课程四(Convolutional Neural Networks),第四 周(Special applications: Face recognition & Neural style transfer) —— 2.Programming assignments:Art generation with Neural Style Transfer
Deep Learning & Art: Neural Style Transfer Welcome to the second assignment of this week. In thi ...
- Tensflow的targmax函数
一.函数: argmax( input, axis=None, name=None, dimension=None, output_type=tf.int64 ) 简单的说,tf.argmax就是返回 ...
- django--form相关
简单用法: Django提供 Form组件: 1. 定义规则 from django.forms import Form ...
- sql server 备份与恢复系列七 页面还原
一.概述 当数据库发生损坏,数据库的每个文件都能打开,只是其中的一些页面坏了,这种情况可以借助DBCC CHECKDB进行数据库检查修复.如果要保证数据库不丢失,或修复不好,管理员只能做数据库完整恢复 ...
- Android 引用文件(.db)的三种方式
1.assets —— 资产目录(该目录中的文件会被直接打包到 apk 文件中).获取该目录下的文件的方式是: InputStream is = getContext().getAssets().op ...
- MySQL数据库设计规范
1. 规范背景与目的 MySQL数据库与 Oracle. SQL Server 等数据库相比,有其内核上的优势与劣势.我们在使用MySQL数据库的时候需要遵循一定规范,扬长避短.本规范旨在帮助或指导R ...