07.分页
Posted thetree
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了07.分页相关的知识,希望对你有一定的参考价值。
07.分页
使用limita分页
select * from t_user limit startIndex,pageSize;
使用mybatis实现分页,核心sql
-
接口
List<User> getUserLimit(Map<String,Integer> map);
-
mapper.xml
<select id="getUserLimit" parameterType="map" resultMap="UserMap" > select * from t_user limit #{startIndex},#{pageSize} </select>
-
测试
public void getUserLimit(){ SqlSession sqlSession = MybatisUtils.getSqlSession(); UserMapper mapper = sqlSession.getMapper(UserMapper.class); Map<String,Integer> map = new HashMap<String, Integer>(); map.put("startIndex",0); map.put("pageSize",2); List<User> userList = mapper.getUserLimit(map); for (User user : userList) { System.out.println(user); } sqlSession.close(); }
使用RowBounds实现分页,不再使用sql分页
-
接口
List<User> getUserByRowBounds();
-
mapper.xml
<select id="getUserByRowBounds" resultMap="UserMap" > select * from t_user </select>
-
测试
public void getUserByRowBounds(){ SqlSession sqlSession = MybatisUtils.getSqlSession(); RowBounds rowBounds = new RowBounds(0,3); List<User> User = sqlSession.selectList("com.believe.mapper.UserMapper.getUserByRowBounds",null,rowBounds); for (User user : User) { System.out.println(user); } sqlSession.close(); }
以上是关于07.分页的主要内容,如果未能解决你的问题,请参考以下文章
FragmentStatePagerAdapter 视图分页器片段在活动重新创建后不显示