mybatis从零阅读(一)大纲

工作三年,最近跳槽找工作才深感自己平时积累不足
决定多看代码多写博客,算是现在定下的2019目标吧。(虽然有点晚,但在路上)
源码是一个艰巨而漫长的过程,那就从简单一点的mybaties开始。

mybatis的使用过程

    String resource = "mybatis-config.xml";

InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

SqlSession session = sqlSessionFactory.openSession();
try {
        BlogMapper mapper = (BlogMapper) session.getMapper(BlogMapper.class);
        System.out.println(mapper.selectBlog());
finally {
        session.close();
}

mybatis的具体过程可分解为

    1.根据路径加载XML,加载JDBC配置
2.加载mapper,将sql和对应的ID关联起来()
3.根据XML配置完成连接池的初始化
4.连接池获取连接,拿参数并进行SQL动态拼接
5.返回结果的封装(实体类的映射和resultype)
6.复杂日志系统的兼容
posted @ 2019-07-07 15:41  Kotlin  阅读(171)  评论(0编辑  收藏  举报
Live2D