select * from user_k uk limit 1,2;
select * from user_k uk limit 2; #[0,2]
List<UserK> getUsersByLimit(Map<String, Integer> map);
<select id="getUsersByLimit" parameterType="map" resultType="com.qlx.pojo.UserK">
select * from mybatis.user_k uk limit #{startIndex},#{pageSize}
</select>
public class demo {
SqlSession sqlSession = MyBatisUtils05.getSqlSession();
UserKMapper05 mapper = sqlSession.getMapper(UserKMapper05.class);
@Test
public void testUsersByLimit() {
HashMap<String, Integer> map = new HashMap<>();
map.put("startIndex", 1);
map.put("pageSize", 2);
List<UserK> users = mapper.getUsersByLimit(map);
users.forEach(System.out::println);
}
}
List<UserK> getUsersByRowBounds();
<select id="getUsersByRowBounds" resultMap="BaseResultMap">
select *
from mybatis.user_k
</select>
@Test
public void testUsersByRowBounds() {
RowBounds rowBounds = new RowBounds(1, 2);
//通过java代码实现分页
List<UserK> userKList = sqlSession.selectList("com.qlx.mapper.UserKMapper05.getUsersByRowBounds", null, rowBounds);
for (UserK userK : userKList) {
System.out.println(userK);
}
}
官网写的很详细了直接上官网链接:
? https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md
原文:https://www.cnblogs.com/lxsfve/p/13726912.html