select * from user limit 3;
mybatis实现分页、核心是sql
1、接口
2、mapper.xml
<select id="getUserByLimit" parameterType="map" resultMap="UserMap">
select * from mybatis.user limit #{startIndex},#{pageSize}
</select>
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
HashMap<String, Integer> map = new HashMap<>();
map.put("startIndex", 0);
map.put("pageSize",1);
List<User> userList = mapper.getUserByLimit(map);
for (User user : userList) {
System.out.println(user);
}