语法:select * from user limit startIndex,pageSize
select * from user limit 0,2
mybatis分页查询
-
添加接口
// 分页查询
List<User> getUserListLimit(Map<String,Object> value); -
映射绑定
<select id="getUserListLimit" parameterType="map" resultMap="userResultMap">
select * from `user` limit #{startIndex},#{pageSize}
</select> -
测试
@Test
public void TestLimit(){
SqlSession sqlSession = MybatisUntil.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
Map<String, Object> stringObjectHashMap = new HashMap<String, Object>();
stringObjectHashMap.put("startIndex",0);
stringObjectHashMap.put("pageSize",2);
List<User> userListLimit = mapper.getUserListLimit(stringObjectHashMap);
for (User user : userListLimit) {
logger.info(user.toString());
}
sqlSession.close();
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/289026.html