学习目标
- 分页查询
- 使用注解
- 高级查询
- 延迟加载
- xml中的字符实体
- 逆向工程
12.分页查询
分为:物理分页和逻辑分页
12.1.使用Limit分页
物理分页:
使用Mybatis实现分页,核心SQL
接口
//limit分页
List<User> getUserByLimit(Map<String,Integer> map);
mapper.xml
<!--limit分页-->
<select id="getUserByLimit" parameterType="java.util.Map" resultType="com.zpc.mybatis.pojo.User">
select * from tb_user limit #{startIndex},#{pageSize};
</select>
测试
@Test
public void getUserByLimit(){
//利用键值对
Map<String,Integer> map=new HashMap<String,Integer>();
map.put("startIndex",0);
map.put("pageSize",1);
List<User> userByLimit = this.userMapper.getUserByLimit(map);
for (User user : userByLimit) {
System.out.println(user);
}
}
12.2.使用RowBounds分页
逻辑分页:不适合更改频率高的
不再使用SQL实现分页
接口
//RowBounds分页