WHCSRL 技术网

mybatie数据库分页

sqlserver 分页

 SELECT TOP 2 * FROM [user] --显示两行
 WHERE [user].ID
 NOT IN
 (SELECT TOP(1)  ID FROM [user]) --不要第一行
  • 1
  • 2
  • 3
  • 4

mysql

SELECT * FROM table LIMIT 1,2
  • 1

mapper

List<User> getUserListFy(Map<String,Object>map);
  • 1
    <select id="getUserListFy" parameterType="map" resultType="com.wyl.pojo.User">
          SELECT TOP ${row} * FROM [user]
            WHERE [user].ID
             NOT IN
            (SELECT TOP(${uprow})  ID FROM [user])
     </select>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
 @Test
    public void selectfy() {
        //第一步获取sqlsession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        //方式1
        UserMapper UserDao = sqlSession.getMapper(UserMapper.class);
        Map<String, Object> map = new HashMap<>();
        map.put("row",1);
        map.put("uprow",1);
        List<User> userListFy = UserDao.getUserListFy(map);

        for (User user : userListFy) {
            System.out.println(user);
        }
        //关闭
        sqlSession.close();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

  • 1
推荐阅读