蘇阿細 - 分页
type: channel
link: https://www.wangchouchou.com/tag/%E5%88%86%E9%A1%B5/
items: 分页

分页
type: item
date: 2020-12-13T14:06:00+00:00
description: 分页使用的Limit分页：--语法：SELECT * FROM USER LIMIT startIndex,pageSize SELECT * FROM USER LIMIT 0,2; --每页显示2条数据，从0开始查使用Mybatis分页：1、接口//分页 List<User> getUserByLimit(Map<String,Integer> map);2、UserMapper.xml select * from user limit #{startIndex},#{pageSize}; 3、测试package com.sw.test; import com.sw.dao.UserMapper; import com.sw.pojo.User; import com.sw.utils.MybatisUtils; import org.apache.ibatis.session.SqlSession; import org.junit.Test; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Author suaxi * @Date 2020/12/11 17:08 */ public class UserDaoTest { @Test public void getUserByLimit(){ SqlSession sqlSession = MybatisUtils.getSqlSession(); UserMapper mapper = sqlSession.getMapper(UserMapper.class); Map<String, Integer> map = new HashMap<>(); map.put("startIndex",0); map.put("pageSize",2); List<User> userlist = mapper.getUserByLimit(map); for (User user : userlist) { System.out.println(user); } sqlSession.close(); } }RowBounds分页：不再使用sql实现分页1、接口//分页2 List<User> getUserByRowBounds();2、UserMapper.xml select * from user; 3、测试package com.sw.test; import com.sw.dao.UserMapper; import com.sw.pojo.User; import com.sw.utils.MybatisUtils; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.junit.Test; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Author suaxi * @Date 2020/12/11 17:08 */ public class UserDaoTest { @Test public void getUserByRowBounds(){ SqlSession sqlSession = MybatisUtils.getSqlSession(); //RowBounds RowBounds rowBounds = new RowBounds(0, 2); List<User> userList = sqlSession.selectList("com.sw.dao.UserMapper.getUserByRowBounds", null, rowBounds); for (User user : userList) { System.out.println(user); } sqlSession.close(); } } PageHelper链接：https://pagehelper.github.io/