Limit分页

分页本质上还是查询,就是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分页

posted @   小罗要有出息  阅读(80)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示