当前位置: 首页 > news >正文

MyBatis: 分页插件PageHelper直接传递分页参数的用法

一、加分页插件依赖

        <dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.2.13</version></dependency>

二、配置分页插件,并配置相关属性:

    <plugins><plugin interceptor="com.github.pagehelper.PageInterceptor"><property name="supportMethodsArguments" value="true"/></plugin></plugins>

三、定义mapper,并在接口中定义页号和页大小(参数通常不能改)

    <select id="selectCountry2" resultType="cn.edu.tju.domain.Country" >select  * from country</select>
    List<Country> selectCountry2(@Param("pageNum")int pageNum, @Param("pageSize")int pageSize);

四、调用时传入页号和页大小:

package cn.edu.tju.test;import cn.edu.tju.domain.Country;
import cn.edu.tju.mapper.PersonMapper;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;
import java.util.List;public class MyBatisTest10 {public static void main(String[] args) throws IOException {SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));SqlSession sqlSession = sqlSessionFactory.openSession();List<Country> countries = sqlSession.getMapper(PersonMapper.class).selectCountry2(1, 2);System.out.println(countries.size());System.out.println(countries);}
}
http://www.lryc.cn/news/164871.html

相关文章:

  • Python基于Flask的高校舆情分析,舆情监控可视化系统
  • Python第一次作业练习
  • InstallShield打包升级时不覆盖原有文件的解决方案
  • 服务器巡检表-监控指标
  • 无涯教程-JavaScript - DDB函数
  • uniapp打包微信小程序。报错:https://api.weixin.qq.com 不在以下 request 合法域名列表
  • stm32之31.iic
  • 新的 ChatGPT 提示工程技术:程序模拟
  • 【Python】爬虫基础
  • leetcode分类刷题:队列(Queue)(三、优先队列用于归并排序)
  • 无线窨井水位监测仪|排水管网智慧窨井液位计安装案例
  • 024 - STM32学习笔记 - 液晶屏控制(一) - LTDC与DMA2D初始
  • Python数据容器:dict(字典、映射)
  • 2023年基因编辑行业研究报告
  • Spring MVC:请求转发与请求重定向
  • 按键灯待机2秒后灭掉
  • SpringBoot通过自定义注解实现日志打印
  • 代码随想录算法训练营第七天 |151.翻转字符串里的单词
  • 【WebRTC---源码篇】(十:一)WEBRTC 发送视频RTP包
  • cmd 90 validate error!(达梦数据库日志报错)
  • Shape Completion Enabled Robotic Grasping
  • 【C++】构造函数意义 ( 构造函数显式调用与隐式调用 | 构造函数替代方案 - 初始化函数 | 初始化函数缺陷 | 默认构造函数 )
  • VMware16安装ghost版win7
  • 项目集成swagger,访问不到swagger页面
  • 微信小程序怎么隐藏顶部导航栏(navigationBar)变透明的解决方案
  • RabbitMQ基础概念-02
  • 从构建者到设计者的低代码之路
  • Linux创建进程 及父子进程虚拟空间 多进程GDB调试
  • uni-app 之 表格设置
  • Linux易混淆知识点