6.分页
通过分页减少数据量
6.1通过limit分页
select * from user limit 0,5 //检索记录行 1-5
SELECT * FROM table LIMIT 5; //检索前 5 个记录行
mybatis实现limit分页
接口
List<User> getUserByLimit(Map<String,Integer>map);
映射配置文件:
<resultMap id="UserMap" type="com.Z.pojo.User">
<result column="id" property="id"></result>
</resultMap>
<select id="getUserByLimit" parameterType="map" resultMap="UserMap">
select * from user limit #{startIndex},#{pageSize}
</select>
测试代码中对map进行初始化即可
@Test
public void limitTest(){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
IUserMapper iUserMapper = sqlSession.getMapper(IUserMapper.class);
HashMap<String,Integer> map = new HashMap<String, Integer>();
map.put("startIndex",0);
map.put("pageSize",2);
List<User> userList = iUserMapper.getUserByLimit(map);
for(User user:userList){
System.out.println(user);
}
sqlSession.close();
}