码迷,mamicode.com
首页 > 其他好文 > 详细

07.分页

时间:2020-05-22 09:25:31      阅读:44      评论:0      收藏:0      [点我收藏+]

标签:use   lse   ESS   public   limit   owb   使用   sele   parameter   

07.分页

使用limita分页

select * from t_user limit startIndex,pageSize;
使用mybatis实现分页,核心sql
  1. 接口

    List<User> getUserLimit(Map<String,Integer> map);
    
  2. mapper.xml

    <select id="getUserLimit" parameterType="map" resultMap="UserMap" >
    	select * from t_user limit #{startIndex},#{pageSize}
    </select>
    
  3. 测试

    public void getUserLimit(){
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            Map<String,Integer> map = new HashMap<String, Integer>();
            map.put("startIndex",0);
            map.put("pageSize",2);
            List<User> userList = mapper.getUserLimit(map);
            for (User user : userList) {
                System.out.println(user);
            }
            sqlSession.close();
        }
    
使用RowBounds实现分页,不再使用sql分页
  1. 接口

    List<User> getUserByRowBounds();
    
  2. mapper.xml

    <select id="getUserByRowBounds" resultMap="UserMap" >
    	select * from t_user
    </select>
    
  3. 测试

    public void getUserByRowBounds(){
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            RowBounds rowBounds = new RowBounds(0,3);
            List<User> User = sqlSession.selectList("com.believe.mapper.UserMapper.getUserByRowBounds",null,rowBounds);
            for (User user : User) {
                System.out.println(user);
            }
            sqlSession.close();
        }
    

07.分页

标签:use   lse   ESS   public   limit   owb   使用   sele   parameter   

原文地址:https://www.cnblogs.com/thetree/p/07_mybatis.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!