mybatis0070- 一次简单查询的执行过程

    xiaoxiao2024-12-21  67

    文章目录

    一次简单查询1. [解析xml配置文件,生成SqlSessionFactory](https://blog.csdn.net/wrongyao/article/details/90575448)2. [通过SqlSessionFactory创建sqlSession](https://blog.csdn.net/wrongyao/article/details/90576026)3. [Mapper接口到SqlSession的跨越](https://blog.csdn.net/wrongyao/article/details/90576828)4. [SqlSeesion执行sql语句](https://mp.csdn.net/postedit/101426262) githup项目地址

    一次简单查询

    public class Test { public static void main(String[] args) { try { String resource = "mybatis.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sqlSessionFactory.openSession(); SysRoleMapper sysRoleMapper = sqlSession.getMapper(SysRoleMapper.class); SysRole sysRole = sysRoleMapper.selectById(1); System.out.println(sysRole); sqlSession.close(); } catch (IOException e) { e.printStackTrace(); } finally { } } }

    上述过程可以分为下面几个步骤

    1. 解析xml配置文件,生成SqlSessionFactory

    2. 通过SqlSessionFactory创建sqlSession

    3. Mapper接口到SqlSession的跨越

    4. SqlSeesion执行sql语句

    最新回复(0)