分页本质上还是查询,就是sql语句和要传的参数不一样罢了
1、接口方法
//分页
List<User> getUserByLimit(Map<String,Object> map);
2、Mapper.xml配置文件
<!--分页-->
<select id="getUserByLimit" resultMap="userMap" parameterType="map">
select * from mybatis.user limit #{pageIndex},#{pageSize}
</select>
3、实现
public void getUserByLimit(){
SqlSession sqlSession = sqlSessionFactory.getsqlSession();
userMapper mapper = sqlSession.getMapper(userMapper.class);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("pageIndex",0);
map.put("pageSize",2);
List<User> userLimit = mapper.getUserByLimit(map);
for (User user : userLimit) {
System.out.println(user);
}
}
当然分页不止这点东西,还有RowBounds这类的工具,但本质还是Limit分页