如何使用mybatis框架完成开发
1:导入依赖
2:复制配置文件!!!!!
3:相关的的javabean
4:测试
4.1 工程队 SqlSessionFactoryBuilder
4.2 builder对象调用bulid(InputStream)得到了SqlSessionFactory
4.3 SqlSessionFactory中openSession() 得到 SqlSession对象
4.4 使用接口中方法 selectList(SQLID) 就可以执行sql语句并获取结果集
4.5 释放资源
@Test
public void queryList() throws IOException {
SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
SqlSession sqlSession = sqlSessionFactory.openSession();
List<User> list = sqlSession.selectList("userMapper.queryList");
list.forEach(System.out::println);
sqlSession.close();
}