mybatis分页查询
方法一:1.petMapper.xml
<select id="selectAll" parameterType="Map" resultType="Pet">select * from pet limit #{startIndex},#{pageSize}
</select>
2.PetDao.java
public List<Pet> selectAll(int currentPage,int pageSize) throws IOException{SqlSession sqlSession = MyBatisUtil.getSqlSession();Map<String,Integer> map=new HashMap<String, Integer>();map.put("startIndex", (currentPage-1)*pageSize);map.put("pageSize",pageSize);List<Pet> pets=sqlSession.selectList("com.mybatis.entity.PetMapper.selectAll",map);return pets;}
3.测试类
public static List<Pet> selectAll(int currentPage,int pageSize) throws IOException {PetDao petDao=new PetDao();List<Pet> pets=petDao.selectAll(currentPage,pageSize);return pets;}public static void main(String[] args) throws IOException, ParseException {PetDao petDao=new PetDao();List<Pet> pets=petDao.selectAll(1, 2);for(Pet pet:pets) {System.out.println(pet);}}
方法二 1.PetMapper.xml
<select id="getAll" resultType="Pet">select * from pet
</select>
2.PetDao.java
public List<Pet> getAll(int currentPage,int pageSize) throws IOException{SqlSession sqlSession = MyBatisUtil.getSqlSession();RowBounds rowBounds=new RowBounds((currentPage-1)*pageSize,pageSize);List<Pet> pets=sqlSession.selectList("com.mybatis.entity.PetMapper.getAll",null,rowBounds);return pets;}
3.测试类
public static List<Pet> getAll(int currentPage,int pageSize) throws IOException {PetDao petDao=new PetDao();List<Pet> pets=petDao.getAll(currentPage, pageSize);return pets;}public static void main(String[] args) throws IOException, ParseException {PetDao petDao=new PetDao();List<Pet> pets=petDao.getAll(1, 2);for(Pet pet:pets) {System.out.println(pet);}}
mybatis分页查询相关推荐
- MYBATIS分页查询代码优化
项目场景: mybatis分页查询的时候,需要联动其他系统,把每条数据的用户信息查询出来,用户量很多的时候,出现一次查询需要十几秒的情况. 问题描述 查询出的数据,其实除了当前页的数据,其他的实际上并 ...
- Mybatis 分页查询(实战版)
Mybatis 分页查询 提示:本次基于springboot2.4.1,SQL limit实现的 文章目录 Mybatis 分页查询 前言 例如:使用sqL LIMIT 实现条件查询 一.建立实体类( ...
- 【问题解决】MyBatis分页查询SQL Server2008时出现'@P0' 附近有语法错误
MyBatis分页查询SQL Server2008时出现'@P0' 附近有语法错误" Error querying database. Cause: com.microsoft.sqlser ...
- mybatis 分页查询_MyBatis之分页查询:MyBatis PageHelper
MyBatis,作为目前流行的ORM框架,大大方便了日常开发.而对于分页查询,虽然可以通过SQL的limit语句实现,但是比较繁琐.而MyBatis PageHelper的出现,则解决了这一痛点.这里 ...
- java mybatis分页查询语句_mybatis分页查询的实现(一)
一.总结了mybatis中五种不同实现分页查询的方法 UserMapper.java接口文件 public interface UserMapper { //分页查询 public List sele ...
- Spring Boot实现MyBatis分页查询
综合概述 想必大家都有过这样的体验,在使用Mybatis时,最头痛的就是写分页了,需要先写一个查询count的select语句,然后再写一个真正分页查询的语句,当查询条件多了之后,会发现真的不想花双倍 ...
- 【mybatis】在mybatis分页查询时,主表对关联表 一对多 分页查询怎么实现
现在有这样一个需求: 1.积分商品分页查询 2.一个积分商品会有多张商品图片在商品图片表 1:n的关系 这样在积分商品分页查询的时候,想要顺便把每个积分商品对应的商品图片信息也带出来 实现如下: 1 ...
- mybatis分页查询插件
1.引入jar包 <dependency><groupId>com.github.pagehelper</groupId><artifactId>pag ...
- Mysql+Mybatis分页查询——数据库系列学习笔记
一.首先做一个查询所有并显示 dao public interface ProductDAO {public List<Product> list(); } mapper <mapp ...
- springboot之mybatis分页查询
首先写一个基础的分类bean插件,由下面两个类组成 package com.my.utils;import com.fasterxml.jackson.annotation.JsonFormat; i ...
最新文章
- python工程师-史上最全Python工程师常见面试题集锦,有这一份就够了
- 四级计算机基础知识,全国计算机等级考试四级通关攻略
- Android Scroller用法
- Luogu 4514 上帝造题的七分钟
- [HTML5]使用Box2dWeb模拟飞行箭矢
- 【51nod】最大子段和
- AlbertTransformerEncoder
- linux的系统监视器图片_Linux中一个高效的资源监控器Bpytop
- mariadb.zip压缩包解压后使用绿色db配置方法
- RS232,RS485 标准DB9接口(串口通信线标准接口)
- linux如何进入redis客户端,如何在linux下安装redis及客户端的连接
- 重装win10提示在EFI系统上,Windows只能安装到GPT磁盘
- 数据库异常用户sa登录失败_轻松解决SQLserver2014出现“用户sa登录失败 错误18456”的问题-网络教程与技术
-亦是美网络...
- python爬虫解决频繁访问_python爬虫防止IP被封的一些措施
- 全新动态视频壁纸微信小程序源码下载支持多种分类短视频另外也有静态壁纸
- Endnote Reference styles参考文献引用模版制作——附毕设大论文引用模版
- 读取文件并输出,输出时将小写字母转为大写
- vmware虚拟机连接usb,显示:无法识别的usb设备,跟这台计算机连接的前一个usb设备工作不正常
- C语言编码转换----负数的二进制表示方法
- 我和世界杯的‘恩怨情仇’
热门文章
- Autofac - 属性注入
- [Map 3D开发实战系列] Map Resource Explorer 之四-- Map3D开发中的WPF
- 数据结构与算法(四):二叉树
- Java格式化日期和时间模式占位符
- linux qt libs,linux下qt使用第三方库的那些事
- linux应用程序调试方法,Linux应用程序使用写文件调试程序的方法
- php 字符串判空,php 使用 preg_replace 去除空格后的字符串无法判空
- php文件名函数,php 获取文件名basename()函数的用法总结
- aix6.1 oracle12c,AIX6.1系统 oracle 11g数据库恢复过程
- matlab综合实验研究,MATLAB综合实验报告.doc