<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace=绑定要给对应的Dao/mapper接口-->
<mapper namespace="com.gao.dao.UserMapper">
<!--分页-->
<select id="getUserByLimit" parameterType="map" resultType="com.gao.pojo.User">
select * from mybatis.user limit #{startIndex},#{pageSize};
</select>
</mapper>
package com.gao.dao;
import com.gao.pojo.User;
import com.gao.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import java.util.HashMap;
import java.util.List;
public class UserDaoTest {
@Test
public void getUserByLimit(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
HashMap<String,Integer> map = new HashMap<String,Integer>();
map.put("startIndex",0);
map.put("pageSize",2);
List<User> userList = mapper.getUserByLimit(map);
for (User user : userList){
System.out.println(user);
}
sqlSession.close();
}
}