zoukankan      html  css  js  c++  java
  • Mybatis Limit实现分页

    Limit实现分页

    1.Limit 实现分页:

    1.2编写接口:

     1.3实现接口(mapper):

    <!--    分页-->
    <select id="getUserByLimit" parameterType="map" resultType="com.xiaofu.pojo.User">
         select * from test.user limit #{startIndex},#{pageSize}
    </select>

    1.4 编写测试类:

        @Test
        public void getUserByLimit(){
            //第一步:获取sqlSession对象
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            //第二步:获取mapper对象
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            //第三步:用map将对应的值 存进去
            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
            sqlSession.close();
        }

     运行程序:

  • 相关阅读:
    Sightseeing,题解
    A Simple Problem,题解
    城池攻占,题解
    传递,题解
    How many ways??,题解
    Least Cost Bracket Sequence,题解
    Evacuation,题解
    Tallest Cow,题解
    容易题,题解
    无题Ⅱ,题解
  • 原文地址:https://www.cnblogs.com/love2000/p/14210457.html
Copyright © 2011-2022 走看看