MyBatis的通俗理解:SqlSession.getMapper()源码分析

参考:MyBatis的通俗理解:SqlSession.getMapper()源码分析

笔记:

  1. SqlSession中可以通过getMapper()拿到代理对象,SqlSession.getMapper 运用了 JDK动态代理,产生了目标Mapper接口的代理对象。
     public void getUserByLimit(){
    
            SqlSession sqlSession = MybatisUtils.getSqlSession();
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    
            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.close();
posted @ 2021-11-07 18:55  旷野之息  阅读(582)  评论(0编辑  收藏  举报