分页
limit 设置分页
- 接口
List<User> getUserBylimit(Map<String,Integer> map);
- UserMapper.xml
<select id="getUserBylimit" resultMap="resultMap" parameterType="map">
select * from mybatis.user limit #{start},#{page}
</select>
limit的用法
mysql> SELECT * FROM table LIMIT 5,10; // 检索记录行 6-15
//为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1:
mysql> SELECT * FROM table LIMIT 95,-1; // 检索记录行 96-last.
//如果只给定一个参数,它表示返回最大的记录行数目:
mysql> SELECT * FROM table LIMIT 5; //检索前 5 个记录行
//换句话说,LIMIT n 等价于 LIMIT 0,n。
- Mytest
@Test
public void mytest(){
SqlSession sqlSession=MybatisUtils.getSqlSession();
UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
HashMap<String,Integer> map=new HashMap<String, Integer>();
map.put("start",0);
map.put("page",2);
List<User> userList=userMapper.getUserBylimit(map);
System.out.println(userList);
sqlSession.close();
}