package com.lc.mybatis.test;

import com.lc.mybatis.entity.Dept;
import com.lc.mybatis.entity.User;
import com.lc.mybatis.mapper.DeptMapper;
import com.lc.mybatis.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class TestDeptResultMap {




    @Test
    public void test01() throws IOException {
        //构建sqlSessionfactory
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory  = new SqlSessionFactoryBuilder().build(is);
        //获取 SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession(true);

        //执行sql
        DeptMapper mapper = sqlSession.getMapper(DeptMapper.class);
        Dept dept = mapper.getDeptById(1);

        System.out.println("部门信息："+dept);

        //释放
        sqlSession.close();
    }


}
