mybatis入门 ----------------------------------------------------- //1.读取配置文件 InputStream inputStream = Resources.getResourceAsStream("sqlMapConfig.xml"); //2.创建SQLSessionFactory工厂 SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); SqlSessionFactory factory = builder.build(inputStream); //3.使用工厂生产sqlSession对象 SqlSession session = factory.openSession(); //4.使用SQLSession创建Dao接口的代理对象 IUserDao userDao = session.getMapper(IUserDao.class); //5.使用代理对象执行方法 List<User> list = userDao.findAll(); for (User user :list){ System.out.println(user); } //6.释放资源 session.close(); inputStream.close();
----------------------------------------------------------------