---
# System prepended metadata

title: RowBounds分頁(了解即可)
tags: [Mybatis-分頁]

---

# RowBounds分頁(了解即可)
###### tags: `Mybatis-分頁`

不再使用SQL實現分頁

1.接口
```java=
 List<User> getUserByRowBounds();
```
2.mapper.xml
```xml=
    <select id="getUserByRowBounds" resultMap="UserMap">
        select * from mybatis.user
    </select>
```
3.測試
```java=
@Test
    public void getUserByRowBounds(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();

        //RowBounds實現
        RowBounds rowBounds = new RowBounds(1, 2);

        //通過java代碼層面實現分頁
        List<User> userList = sqlSession.selectList("com.kuang.dao.UserMapper.getUserByRowBounds",null,rowBounds);

        for(User user:userList){
            System.out.println(user);
        }
        sqlSession.close();
    }
```

