接口
//分页
List<User> getUserByLimit(HashMap<String, Integer> map);
Mapper.xml
<!-- //分页-->
<select id="getUserByLimit" parameterType="map" resultMap="UserMap">
select *from mybatis.user limit #{stratIndex} ,#{pageSize}
</select>
测试
@Test
public void getUserByLimit() {
//第一步 获取sqlSession对象
SqlSession sqlSession = MybatisUtils.getSqlSession();
//第二步 执行sql
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
HashMap<String, Integer> map = new HashMap<>();
map.put("stratIndex",0);
map.put("pageSize",2);
List<User> userList = mapper.getUserByLimit(map);
for (User user : userList) {
System.out.println(user);
}
//关闭sqlSession
sqlSession.close();
}